Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: 'module' object has no attribute 'reader' [duplicate]

Tags:

python

csv

I get the error:

AttributeError: 'module' object has no attribute 'reader')

when I run the code below but I can't see why?

import csv

with open('test.csv') as f:
    q = csv.reader(f)
like image 368
Tom Lowbridge Avatar asked Feb 11 '16 13:02

Tom Lowbridge


1 Answers

You imported a different csv module, not the one in the standard library. Perhaps you named your own script csv.py for example.

Find out what is imported instead by printing out the filename of the module:

import csv
print(csv.__file__)

If that's not in the standard library, rename or delete this file, and remove the csv.pyc file if there is one next to it.

like image 152
Martijn Pieters Avatar answered Oct 15 '22 13:10

Martijn Pieters