2019-06-09 14:02发布

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条回答
倾城 Initia
2楼-- · 2019-06-09 14:34
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

查看更多
登录 后发表回答