阅读和写作的Python错误

时间:2017-07-24 13:10:48

标签: python csv

import csv 
dataList = []

with open('N004_timetable.csv', 'rb') as csvfile:
    csvreader = csv.reader(csvfile)
    for row in csvreader:
        dataList.append[row]

csvfile.close()

print(dataList[2][2])

当我运行此代码时,我收到此错误

Traceback (most recent call last):
  File "C:\attendance\Class.py", line 5, in <module>
    for row in csvreader:
_csv.Error: iterator should return strings, not bytes (did you open the file in text mode?)

我尝试过做

with open('N004_timetable.csv', 'rt') as csvfile:

我收到此错误

Traceback (most recent call last):
  File "C:\attendance\Class.py", line 6, in <module>
    dataList.append[row]
TypeError: 'builtin_function_or_method' object is not subscriptable

我做错了什么?

0 个答案:

没有答案