【发布时间】:2019-01-18 08:36:18
【问题描述】:
这是我从一些数据读取到 MySql 的代码,Mysql 表包含 3 列,在其中一个列中我想插入一个数组的项,每一个都插入一个新行,我不想重复行:
db = MySQLdb.connect("127.0.0.1", "root", "M0", "my", local_infile=True,use_unicode=True, charset="utf8")
cursor = db.cursor()
r=["2","3"]
params = ['?' for item in r]
sql="insert ignore into array (firt,last_name,arrays) values 'nina','sa',(%s);" % ','.join(params)
cursor.execute(sql,r)
db.commit();
db.close()
我也已经看过[1]这个帖子了!
但是,在他们两个上我都收到了这个错误:
_mysql_exceptions.ProgrammingError: not all arguments converted during string formatting
有什么建议吗?
【问题讨论】:
-
你试过打印你的参数吗?
-
请打印您的查询(使用实际参数值)并显示出来。
-
@mad_ ,刚刚做到了!表明 ”?” !!!为什么会这样?
-
您正在迭代 n 次并分配 '?'每一次。你真的不需要你的参数列表。更正并编辑帖子
-
@mad_ 我更正了,我没有为列表分配参数!但收到已发布的错误。