数据未插入我的选项卡

2024-06-17 13:18:54 发布

您现在位置:Python中文网/ 问答频道 /正文

import MySQLdb
import csv
mydb = MySQLdb.connect(host='localhost',user='root',passwd='root', db='kabir')
cursor = mydb.cursor()

data = csv.reader(file('data.csv'))

#cursor.execute('create table actors(name varchar(20),age integer)')                                                                                                                                                               
for row in data:
    cursor.execute('INSERT INTO actors(name,age) VALUES(%s %s)' ,row)
mydb.commit()
cursor.close()

Tags: csvnameimportlocalhosthostexecuteagedata
1条回答
网友
1楼 · 发布于 2024-06-17 13:18:54

您没有在%s和%s之间指定逗号。请将其更改为:

cursor.execute('INSERT INTO actors(name,age) VALUES(%s, %s)' ,row)

试着。。你知道吗

相关问题 更多 >