[英]Python 3.3 IndexError doesn't make sense
我在py3.3中有一个多维数组,看起来像
[ # big container
[ # month container
['date string', 'temp'],['date string', 'temp'] #dates in month
], #close month container
[ # next month container
['date string', 'temp'], ['date string', 'temp']
]
]
这是我的代码:
dailyDict = []
dailyRow = []
compareStation = 'myfile.csv'
with open(compareStation, newline='\n') as csvfile:
station = csv.reader(csvfile, delimiter=',', quotechar='|')
for row in station:
if 1stDayOfMonthCondition:
dailyDict.append(dailyRow)
dailyRow = []
dailyRow.append(row)
else:
dailyRow.append(row)
for month in dailyDict:
print(month[1])
这给了我一个IndexError,列出了超出范围的索引。 但是,当我运行print(month)
每个月都可以打印出来。
当我在外壳中将打印月份设置为变量x
,我可以正常print(x[1])
。 但是print(month[1])
仍然失败。 很迷茫。
谢谢。
索引列表从0而不是1开始,因此您应该尝试使用print(month[0])
来查看是否有这种方式
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.