[Tutor] reading a csv file

Alan Gauld alan.gauld at btinternet.com
Tue Apr 15 10:10:44 CEST 2014


On 15/04/14 07:06, Sunil Tech wrote:
> Hi,
>
> #!/usr/bin/python
>
> import csv
> import sys
>
> def main():
>      cr = csv.reader(open("data.csv","rb"))
>      for row in cr:
>          print row

> when i run this...
>
>      cr = csv.reader(open("data.csv","rb"))
> AttributeError: 'module' object has no attribute 'reader'
>

The most common cause of this error is that you have
created a file called csv.py which is masking the
library module.

Could that be the case here?


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list