Importing a csv file

S

sagar

Hi all ,
I want to read data in a csv file using the python scripts.
when i gave the following code :
import csv
reader = csv.reader(open("some.csv", "rb"))
for row in reader:
print row

it is showing :

Traceback (most recent call last):
File "csv.py", line 1, in <module>
import csv
File "C:\Documents and Settings\meesa02\csv.py", line 2, in <module>
reader = csv.reader(open("some.csv", "rb"))
AttributeError: 'module' object has no attribute 'reader'

im a total fresher to this python...SO can any one help me out in
this...

Thanks in advance
Sagar Meesala
 
T

Tim Golden

sagar said:
Hi all ,
I want to read data in a csv file using the python scripts.
when i gave the following code :
import csv
reader = csv.reader(open("some.csv", "rb"))
for row in reader:
print row

it is showing :

Traceback (most recent call last):
File "csv.py", line 1, in <module>
import csv
File "C:\Documents and Settings\meesa02\csv.py", line 2, in <module>
reader = csv.reader(open("some.csv", "rb"))
AttributeError: 'module' object has no attribute 'reader'

You almost certainly have a file called "csv.py" in
the current directory. (Maybe even the one that's
running this script?). Rename it to "mycsv.py" or
whatever and try again.

TJG
 
J

John Machin

Only *almost* certainly, Tim? *Maybe*? You don't believe what the
above traceback lines are telling you?
 
T

Tim Golden

John said:
Only *almost* certainly, Tim? *Maybe*? You don't believe what the
above traceback lines are telling you?

It's my natural British diffidence :) We almost never make
unqualified statements.

TJG
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top