python错误:列表索引超出范围

python错误:列表索引超出范围,python,python-2.7,set,Python,Python 2.7,Set,我不断得到错误: line 39, in fetchLocations locations.add(row[-1]) IndexError: list index out of range 对于以下代码 def fetchLocations(filename): locations = set() with open(filename, 'rU') as fileObject: csvFile = csv.reader(fileObject, delimiter = ',',

我不断得到错误:

line 39, in fetchLocations
locations.add(row[-1])
IndexError: list index out of range
对于以下代码

def fetchLocations(filename):
  locations = set()
  with open(filename, 'rU') as fileObject:
    csvFile = csv.reader(fileObject, delimiter = ',', quotechar = '"')
    for row in csvFile:
        #print row[-1]
        locations.add(row[-1])
  return locations
但是,如果我取消注释

print row[-1]

它很好用。有什么线索可以解释为什么会这样吗

如果将“打印行[-1]”替换为值=行[-1];印刷价值;add(value)@user1474424是的,我也发现了。然而,csv文件有大约2500万行!因此,打印出所有这些大大增加了执行时间。想知道为什么会这样!