python向数据库插入数据时报错%d format: a number is required, not str
生活随笔
收集整理的這篇文章主要介紹了
python向数据库插入数据时报错%d format: a number is required, not str
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在輸入數據時走入了一個誤區:
我以為既然我要存的是int整型,那么在向表中輸入時insert_sql1='insert into {table} values(%s, %s, %s)'.format(table = table_name)應該改成%s,%s,%t
但是The format string is not really a normal Python format string. You must always use %s for all fields.
MySQLdb的字符串格式化不是標準的python的字符串格式化,應當一直使用%s用于字符串格式化。
總結
以上是生活随笔為你收集整理的python向数据库插入数据时报错%d format: a number is required, not str的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python如何装sklearn_pyt
- 下一篇: websocket python爬虫_p