python脚本更新数据库报错:TypeError: %d format: a number is required, not str

很悲催的是我写错了,之前的插入没有问题。但是更新就报错了,本身就是我的写法有错误,有必要记录一下。

插入语句是没有问题的,这是因为所有项都是字符串。

con.execute("insert into b(isbn, bn, bk, bs, author, publisher, publishdate) values (%s,%s,%s,%s, %s, %s, %s)",([isbn, bn, bk, bs, author, publisher, publishdate]))

一旦有数字就完了,就会报上面的错误。

更改如下:

con.execute("update b set maxstore=(%d) where bk='医药'"%(a))

OK~

原文地址:https://www.cnblogs.com/AbsolutelyPerfect/p/7805712.html