【发布时间】:2015-08-06 21:47:16
【问题描述】:
所以我的代码如下所示:
with open(completeCSV, 'r') as csvfile:
test = csv.reader(csvfile, delimiter=';')
for line in test:
print(line)
i = i + 1 # on the first line, i will equal 1
count = line[0]
if count == '1':
for prof in proflist: # vertex1=prof
if line[1].lower() == proflist[prof]:
# if vertex1 is a professor, you want to keep the edge.
lines_to_keep.append(i)
break # breaks and doesn't check the rest of profs
它基本上读取 CSV,并检查 csv 中的值是否等于列表 proflist 中的另一个值。
我收到此错误:
Traceback(最近一次调用最后一次): 文件“C:/Users/sskadamb/PycharmProjects/BetterDelimiter/filter.py”,第 50 行,在 如果 line[1].lower()==proflist[prof]: TypeError: 列表索引必须是整数,而不是 str
是因为proflist[prof]吗?但我想检查所有条目
proflist 反对 line[1]。我该怎么做,我做错了什么?我可以不迭代这样的列表吗?
【问题讨论】:
-
prof是proflist的元素,而不是索引 -
我明白了.. 谢谢。那我可以
if line[1]==prof吗?