python mysql类型

2024-06-28 13:13:43 发布

您现在位置:Python中文网/ 问答频道 /正文

在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字段

我很困惑,因为curRowcurCol显然属于{},而{}意味着给我一个{}。python作为一个字符串有什么令人困惑的地方?在


Tags: 代码infrom类型executetypecountline