0

I couldn't understand while file is not considered by the interpreter

csv_data = csv.reader(file('D:\\Eclipse_Python\\Python\\com\\praveen\\pandas\\iplStats.csv'))

for row in csv_data:
    print(row)
    cur.execute('PREPARE stmt FROM INSERT INTO praveendb.iplstats (Wins,Losses,Year,Loss,Team) VALUES(?,?,?,?,?)', row)

ERROR:

Traceback (most recent call last):
  File "D:\Eclipse_Python\Python\pandasLibDataFrame.py", line 28, in <module>
    csv_data = csv.reader(file('D:\\Eclipse_Python\\Python\\pandas\\iplStats.csv'))
NameError: name 'file' is not defined

1 Answer 1

1

I assume you are suing Python 3. If you are using Python 3. File() is not availabe instead use open()

import csv

with open('yourfile.csv') as csv_file:
    do you code 
Sign up to request clarification or add additional context in comments.

1 Comment

in addition to what @Backtrack said, use with context manager - both for reading the file and connecting to the database

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.