python3.3索引器不支持sens

2024-10-04 03:20:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我在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])仍然失败。非常困惑

谢谢


Tags: csvcsvfileindatestringcontainertemprow