• Register
0 votes
1.4k 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?)
6 5 3
6,930 points

Please log in or register to answer this question.

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)
9 7 4
38,600 points

Related questions

0 votes
1 answer 11 views
11 views
Problem: how i can move on in dealing with this situation ? Iterator should return strings, not bytes (did you open the file in text mode?.
asked Mar 6 Wafa Abu Yousef 6.1k points
0 votes
1 answer 2.9K views
2.9K views
Problem : MySample.csv contains the below details : NAME Id No Dept Tommy 1 12 CS Jimmy 2 35 EC Bonny 3 21 IT Franky 4 61 EE And my Python file contains the below code : import csv myifile = open('mysample.csv', "rb") read = csv.reader(myifile) for row in read : ... in for row in read : _csv.Error: iterator should return strings, not bytes (did you open the file in text mode?) How should I fix it?
asked Jan 2, 2020 alecxe 7.5k points
0 votes
1 answer 3 views
3 views
Problem: Who can help me to fix an error showing in my computer that error: iterator should return strings, not bytes (did you open the file in text mode?)
asked Mar 26 ashik 10.7k points
0 votes
1 answer 9 views
9 views
Problem: I am facing following error: post data should be bytes, an iterable of bytes, or a file object. it cannot be of type str.
asked Mar 14 Wafa Abu Yousef 6.1k points
0 votes
1 answer 1.7K views
1.7K views
Problem : I am trying to convert my working Python 2.7 code into Python 3 code but I am facing following error post data should be bytes, an iterable of bytes, or a file object. it cannot be of type str.
asked Nov 16, 2019 peterlaw 6.9k points
0 votes
1 answer 720 views
720 views
Probem : I am getting bellow error new-line character seen in unquoted field - do you need to open the file in universal-newline mode?
asked Nov 7, 2019 peterlaw 6.9k points
0 votes
1 answer 8 views
8 views
Problem: after upgrading to 3.5, I'm getting the: TypeError: a bytes-like object is required, not 'str'
asked Mar 16 ummesalma 22.9k points
0 votes
1 answer 307 views
307 views
Problem : When I try to run following command: python manage.py updatestats I get the error as below: “TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'” I am unable to figure out ... ) File "/Users/alecxe/project/Dev/project_files/project/main/management/commands/updatestats.py", line 34, in handle unique_visits=display_unique_visits(hostname),)
asked Jan 2, 2020 alecxe 7.5k points
0 votes
1 answer 2.5K views
2.5K views
Problem : I am facing the issue in passing a function as a parameter to another function as follows typeerror: int() argument must be a string, a bytes-like object or a number, not 'nonetype'
asked Nov 18, 2019 peterlaw 6.9k points
0 votes
2 answers 125 views
125 views
Problem : I have recently installed the cuda 8.0 and cuda 9.0 in the Gpu support system. I encountered the below error while importing from the keras module. It says it is unable to load the native tensorflow runtime. I have received the error log as below: Traceback ... is, Cuda compilation tools, release 8.0, V8.0.61 Is it the clash between two cuda versions? Have anyone solved this before?
asked Feb 18, 2020 mphil 2.3k points