前置条件:
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))
- Hussain