Python3 IndexError:列表索引超出范围

时间:2018-09-19 15:20:01

标签: python-3.x

我想从.CSV读取数据。

import csv

def read_file(locs):
    with open("/Users/macbookpro/Documents/commit/out.csv") as f:
        reader= csv.reader(f)
        for row in reader:
            locs.append(int(row[3]))
        f.close()

locs=[]
read_file(locs)

这是我读取数据的.csv文件。 但是显示错误。

  

回溯(最近通话最近):     文件“ /Users/macbookpro/Documents/testtt.py”,第15行       read_file(位置)     read_file中的文件“ /Users/macbookpro/Documents/testtt.py”,第9行       locs.append(int(row [3]))   IndexError:列表索引超出范围

但是当我在.csv文件中选择较少数量的项目时,它可以成功运行。我不明白。

0 个答案:

没有答案
相关问题