我一直收到错误:
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]
它工作正常。任何线索为什么会发生这种情况!?