c.execute("UPDATE Players SET %s = %d WHERE nick=%s",
(parts[1], int(parts[2]), parts[0]))
显示了错误信息
TypeError: %d format: a number is required, not str
我知道execute
只应该接受%s
,但parts[2]
应该被转换为整数,因为它将作为字符串输入。
因此,如果我仅使用%s
,那么肯定会出现以下错误:
mysql_exceptions.ProgrammingError: (1064,
"You have an error in your SQL syntax; "
"check the manual that corresponds to your MySQL server version "
"for the right syntax to use near "
"''wins' = '450' WHERE nick='xan'' at line 1")
因为wins
是一个整数。
这个问题的解决方法是什么?