def save_db(cons):
db = pymysql.connect(host = '127.0.0.1' , user = 'root' , password = 'root' , port = 3306)
cursor = db.cursor()
sql = 'INSERT INTO quote(jy_time,open_price,high_price,low_price,over_price,zhangdiee,zhangdief,chengjiaol,chengjiaoj,zhenfu,huanshoul) VALUE (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)' print('插入中...')
try:
cursor.execute(sql,(cons)) print(cons)
db.commit()
except: print('失敗了啊')
db.rollback()
db.close()代碼如上,cursor.execute(sql,(cons))是執(zhí)行失敗了么,執(zhí)行結(jié)果:D:\ProgramData\************\python.exe E:/*******/project/test/test.py插入中...
失敗了啊
插入中...
失敗了啊
插入中...明顯是try失敗了,然后就print('失敗了啊')重新捕獲的異常是:not all arguments converted during string formatting是不是因為我插入的是列表不是字符串?
1 回答

Qyouu
TA貢獻1786條經(jīng)驗 獲得超11個贊
Python 3 字符串格式化 不是 "%s-%s" % (1,2)
這么玩嗎 .. 我看好多人用逗號隔開就完事了..
Python3 字符串格式化不可以使用列表進行字符串格式化,一個list只能格式化一個位置
可以的話建議你看看cons
的值,我看你cons
外面又套一個括號.. 變成元組了, 建議排查 待格式化數(shù)據(jù)
添加回答
舉報
0/150
提交
取消