22

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)
John Hascall
  • 9,176
  • 6
  • 48
  • 72
Tom Lowbridge
  • 879
  • 3
  • 9
  • 17

1 Answers1

59

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.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343