• Register
0 votes
1.1k 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 2K views
2K 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 493 views
493 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 1.3K views
1.3K 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 238 views
238 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 1.9K views
1.9K 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 85 views
85 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
0 votes
1 answer 736 views
736 views
Problem : When I am trying to execute jupyter notebook in the virtual environment in my Arch Linux, the below error occurred. “Error executing Jupyter command 'notebook': [Errno 2] No such file or directory” The python version is 3.6, and the jupyter version is 4.3.0 I have researched a lot, but I am just unable to find anything relevant to above issue.
asked Jan 3, 2020 alecxe 7.5k points
0 votes
1 answer 306 views
306 views
Problem : I am very new to the R, and after researching my error as below extensively, I am still unable to find the fix for it. I have already checked my working directory, and also made sure that the files are in a correct directory. Error in file(file, "rt") : ... sulfate", 1:10) In addition: Warning message: In file(file, "rt") : cannot open file './specdata001.csv': No such file or directory
asked Jan 4, 2020 alecxe 7.5k points
0 votes
1 answer 666 views
666 views
Problem : I am trying to use the PyGame for Python, and I have been receiving the below warning while trying to load .png images with pygame.image.load: Libpng warning: Interlace handling should be turned on when using png_read_image It is not affecting the program, but it has become ... : I am currently using 32 bit Python 3.3 with the PyGame 1.9.2 Any pointers as to how can I fix the warning?
asked Jan 2, 2020 alecxe 7.5k points
1 vote
1 answer 204 views
204 views
Problem : I am beginner to Python. Currently if I try to use the request module to have the urls text then I often face below Error: Traceback (most recent call last):  File "/usr/local/lib/python3.6/site-packages/requests-2.18.1-py3.5.egg/requests/adapters.py" ... to get the url's text to parse it. Please find below my line of code for your reference: mytext = requests.get(detail_path).mytext
asked May 2, 2020 stewart 4k points