我不明白翻译器没有考虑文件
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)
错误:
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
答案 0 :(得分:1)
我假设您正在使用Python3。如果您使用的是Python 3,则File()
不可用,而应使用open()
import csv
with open('yourfile.csv') as csv_file:
do you code