在python中,以下代码中的类型有问题:
>>> curRow = 1
>>> curCol = 2
>>> type(curRow)
type 'int'
>>> cur.execute("select COUNT(*) from adjacency where r = %d and c = %d", (curRow, curCol))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build/bdist.macosx-10.8-intel/egg/MySQLdb/cursors.py", line 183, in execute
TypeError: %d format: a number is required, not str
注意r
和{adjacency
中的int
字段
我很困惑,因为curRow
和curCol
显然属于{
因为
.execute()
不仅仅是对传递给它的参数进行%
替换。它首先通过转义来运行它们,然后在这个过程中将值转换为字符串。在请改用
%s
。在相关问题 更多 >
编程相关推荐