在 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
和c
都是int
表中的字段adjacency
我很困惑,curRow
显然curCol
是类型int
,%d
意味着给我一个int
。什么是 python 令人困惑的字符串?