我在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])
这给了我一个索引器,列表索引超出范围。
然而,当我运行print(month)
时,我每个月都能很好地打印出来
当我在shell中将printed month设置为变量时,比如说,x
,我可以print(x[1])
很好。但是print(month[1])
仍然失败。非常困惑
谢谢
索引列表从0开始而不是从1开始,因此您应该尝试
print(month[0])
,看看是否有这样的结果相关问题 更多 >
编程相关推荐