%d format a number is required not str

时光毁灭记忆、已成空白 提交于 2019-12-08 11:15:40

问题


I have a table named tablename with idno as primary kry. I want the row to be deleted if the user specifies the idno in the table. Here are my codes:

data3=raw_input("Enter the idno to del :",)
mydata=cursor.execute("DELETE FROM tablename where idno=%d", data3)
db.commit()

I'm getting this error:

Traceback (most recent call last): File "C:\Python27\trertr.py", line 50, in mydata=cursor.execute("DELETE FROM tablename where idno=%d", data3) File "C:\Python27\lib\site-packages\MySQLdb\cursors.py", line 187, in execute query = query % tuple([db.literal(item) for item in args]) TypeError: %d format: a number is required, not str


回答1:


data3=int(raw_input("Enter the idno to del :",))

cursor.execute("DELETE FROM tablename where idno=%s", [data3])

After a lot of tries, I have got the answer which worked for me



来源:https://stackoverflow.com/questions/43585105/d-format-a-number-is-required-not-str

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!