在命令提示符

时间:2016-04-08 19:29:09

标签: python csv powershell command prompt

我有这些函数给我一个字典。

def zipString2Array(ziplist):
    if ziplist!="-ignored-":
        return ziplist[9:].split(",")
    else:
        return []

def getRegions(quota):
    ## { pid : { rid : [state, ziparray] } }
    regions = {}
    #testing = []
    rows = quota.split("\n")
    for i in rows:
        row = i.split("\t")
        if len(row)>1:
            pid = row[0].strip()
            state = row[10].strip()
            zipstring = row[11].strip()
            ziparray = zipString2Array(zipstring)
            if pid not in regions.keys():

                new = {pid : {"0" : [state,ziparray]}}
                regions.update(new)
            else:
                rid = str(len(regions[pid]) + 1)
                new = {rid : [state, ziparray]}
                regions[pid].update(new)
        #csvfile.close()

            #testing += [pid]

        else:
            pass
    #test = rows[0].split("\t")
    try:
        del regions['Partner ID']
    except KeyError:
        print "exception"
    return regions      

我通过将输入粘贴到命令提示符

将该配额文件传递给getRegions函数
if sys.version_info[0] < 3:
    from StringIO import StringIO
else:
    from io import StringIO

# input csv as pasted string
str_quota = ""
stop = ""
print "Paste Partner Quota Report: "
while True  :
    row = raw_input()
    if row.strip() == stop:
        break
    str_quota +="%s\n" % row

# string to csv
csv_quota = StringIO(str_quota)

程序运行正常,但问题是我面临的问题是从一行中取出4094个字符并留下其余部分。有什么方法可以解决这个问题吗?

0 个答案:

没有答案