如何解决 IndexError:列表索引超出范围

时间:2021-07-22 14:52:50

标签: python-2.7 csv

我是 Python 新手,我有一个包含 35 列的 csv 文件。要打印每个我正在执行的脚本的最后一列:

import csv

filename = '/home/cloudera/PMGE/Bfr.csv'
with open(filename, 'r') as csvfile:
    datareader = csv.reader(csvfile)
    for row in datareader:
        print(row[34])
```
It prints the expected result but at the end i have this error:
```
Traceback (most recent call last):
  File "barplot.py", line 15, in <module>
    print(row[34])
IndexError: list index out of range
```

Can anyone help me to understand this?

0 个答案:

没有答案