%d 格式化数字不是 str [英] %d format a number is required not str

查看:49
本文介绍了%d 格式化数字不是 str的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 tablename 的表,其中 idno 作为主 kry.如果用户在表中指定了 idno,我希望删除该行.这是我的代码:

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()

我收到此错误:

回溯(最近一次调用最后一次):文件C:\Python27\trertr.py",第 50 行,在mydata=cursor.execute("DELETE FROM tablename where idno=%d", data3) File "C:\Python27\lib\site-packages\MySQLdb\cursors.py", line187,在执行query = query % tuple([db.literal(item) for item in args]) TypeError: %d format: a number is required, not str

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

推荐答案

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

这篇关于%d 格式化数字不是 str的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆