我有一个“asin.txt”文件:
in,Huawei1,DE
out,Huawei2,UK
out,Huawei3,none
in,Huawei4,FR
in,Huawei5,none
in,Huawei6,none
out,Huawei7,IT
我正在打开这个文件并制作一个OrderedDict
:
from collections import OrderedDict
reader = csv.reader(open('asin.txt','r'),delimiter=',')
reader1 = csv.reader(open('asin.txt','r'),delimiter=',')
d = OrderedDict((row[0], row[1].strip()) for row in reader)
d1 = OrderedDict((row[1], row[2].strip()) for row in reader1)
然后我想创建变量 (a,b,c,d) 所以如果我们取它的第一行asin.txt
应该是这样 的a = in
:b = Huawei1
; c = Huawei1
; d = DE
. 为此,我使用了“for”循环:
from itertools import izip
for (a, b), (c, d) in izip(d.items(), d1.items()): # here
try:
.......
它以前工作过,但现在,由于某种原因,它会打印一个错误:
d = OrderedDict((row[0], row[1].strip()) for row in reader)
IndexError: list index out of range
我该如何解决?