【发布时间】:2012-01-20 20:26:18
【问题描述】:
Sample.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 中运行上述代码时,出现以下异常:
文件“csvformat.py”,第 4 行,在 对于 read 中的行: _csv.Error: 迭代器应该返回字符串,而不是字节(你是否以文本模式打开文件?)
我该如何解决?
【问题讨论】:
标签: python python-3.x csv