Sample.csv contains the following:
NAME Id No Dept
Tom 1 12 CS
Hendry 2 35 EC
Bahamas 3 21 IT
Frank 4 61 EE
And the Python file contains the following code:
import csv
ifile = open('sample.csv', "rb")
read = csv.reader(ifile)
for row in read :
print (row)
When I run the above code in Python, I get the following exception:
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?)
How can I fix it?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…