【发布时间】:2013-12-26 03:10:06
【问题描述】:
前身:
MySQL Table created via:
CREATE TABLE table(Id INT PRIMARY KEY NOT NULL, Param1 VARCHAR(50))
功能:
.execute("INSERT INTO table VALUES(%d,%s)", (int(id), string)
输出:
TypeError: %d format: a number is required, not a str
我不确定这里发生了什么或为什么我无法执行该命令。这是在 Python 中使用 MySQLdb。 .execute 在光标对象上执行。
编辑:
问题:Python MySQLdb issues (TypeError: %d format: a number is required, not str)
表示您必须对所有字段使用%s。为什么会这样?为什么这个命令有效?
.execute("INSERT INTO table VALUES(%s,%s)", (int(id), string)
【问题讨论】:
-
您缺少
%和)-.execute("INSERT INTO table VALUES(%d,%s)"% (int(id), string))
标签: python mysql mysql-python