Reputation: 13
I'm just at a total loss and can't find anything I understand as being relevant either here at SO or with google.
>>> import csv
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "csv.py", line 6, in <module>
r = csv.read(f)
AttributeError: 'module' object has no attribute 'read'
Upvotes: 0
Views: 842
Reputation: 11387
Your Python script is named csv.py
. You need to rename it to something else. Never name your script with the same name as a module.
Should work after this.
Further, as pointed out in comments, csv
module does not have a read()
method.
Small example from official documentation
>>> import csv
>>> with open('eggs.csv', 'rb') as csvfile:
... spamreader = csv.reader(csvfile, delimiter=' ', quotechar='|')
... for row in spamreader:
... print ', '.join(row)
Spam, Spam, Spam, Spam, Spam, Baked Beans
Spam, Lovely Spam, Wonderful Spam
Upvotes: 1