In Python I have trouble with the following types of code:
& gt; ; & Gt; & Gt; CurRow = 1 & gt; & Gt; & Gt; CurCol = 2> gt; & Gt; & Gt; Type (currow) type 'int' & gt; & Gt; & Gt; Cur.execute ("Select COUNT (*) proximity where r =% d and c =% d", (curRow, curCol) traceback (most recent call final): File "& lt; stdin" , Line 1, in & lt; Module & gt; File "build / bdist.macosx-10.8-intel / egg / MySQLdb / cursors.py", line 183, in the type of type executed:% d format: a number is required, not str Note in the r and c both int fields in the table adjacency
I Very confused as curRow and curCol are clearly written by type int , and % d As a int me What is confusing as a string in a dragon?
Because .execute () doesn you pass it to the replacement of arguments Not just a % , it runs it first by running away, which changes the value in the string in the process. Use % s instead.
No comments:
Post a Comment