csv.Error: iterator should return strings, not bytes

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?

6 Answers
6

Leave a Comment