Programmers learn & share
0 votes
360 views

Problem :

When I run my Python code I get the following exception:
_csv.error: iterator should return strings, not bytes (did you open the file in text mode?)
by (6.9k points)   | 360 views

1 Answer

0 votes

Solution :

I just managed to fixed this issue with my code. The reason behind the exception is the argument rb. Please update that to r.

The Problematic Code:

import csv
icsvfile  = open('sample.csv', "rb")
readcsv = csv.reader(icsvfile)
for row in readcsv :
    print (row) 

New code:

import csv
icsvfile  = open('sample.csv', "r")
readcsv = csv.reader(icsvfile)
for row in readcsv :
    print (row)
by (36.1k points)  
2,245 questions
2,807 answers
60 comments
241 users