示例.csv 包含以下内容:
NAME Id No Dept
Tom 1 12 CS
Hendry 2 35 EC
Bahamas 3 21 IT
Frank 4 61 EE
而Python文件包含以下代码:
import csv
ifile = open('sample.csv', "rb")
read = csv.reader(ifile)
for row in read :
print (row)
当我在Python中运行上述代码时,出现以下异常:
File "csvformat.py", line 4, in for row in read : _csv.Error: iterator should return strings, not bytes (did you open the file in text mode?)
如何解决这个问题?