-3
这是我的代码:蟒蛇CSV读取行,但索引超出范围
with open('example.csv','r',encoding='utf8') as agr:
agr_csv = csv.reader(agr, delimiter=',')
for line in agr_csv:
name = line[0]
year = line[2:3]
countryname[name].append(year)
,但我总是得到这样的错误:
Traceback (most recent call last):
File "quiz_4.py", line 72, in <module>
name = line[0]
IndexError: list index out of range
的原因是什么?
也许还有空行的CSV –
尝试'打印(线)'在你的循环,并写入输出 – Vladyslav