[問題] 插入值到mysql

看板Python作者時間4年前 (2019/12/02 01:22), 4年前編輯推噓3(304)
留言7則, 4人參與, 4年前最新討論串1/1
http://i.imgur.com/2yGxAf8.jpg
我要把資料丟進mysql 可是有錯誤 http://i.imgur.com/7RR7jLM.jpg
想請問要怎麼解決這個問題? 資料庫裡屬性數量是4 程式碼也是4 下面這個是b裡面的格式 http://i.imgur.com/I2hv9IQ.jpg
----- Sent from JPTT on my OPPO CPH1701. -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 223.138.51.78 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1575220933.A.B89.html ※ 編輯: lucy35 (223.138.51.78 臺灣), 12/02/2019 01:23:28

12/02 02:00, 4年前 , 1F
str = ("%s %s %s %s")%(a, b, c, d)
12/02 02:00, 1F

12/02 02:01, 4年前 , 2F
不然就是 (".... vaules({},{},{},{})").format(a,b,c,d)
12/02 02:01, 2F

12/02 02:04, 4年前 , 3F
更正1F(".... values (%s, %s, %s ,%s)")%(a, b , c ,d)
12/02 02:04, 3F

12/02 11:55, 4年前 , 4F
我猜 cursor.execute(insert, b) 就好
12/02 11:55, 4F
會顯示 not all argument converted during string formatting 錯誤 ※ 編輯: lucy35 (223.138.51.78 臺灣), 12/02/2019 20:41:13

12/02 22:10, 4年前 , 5F
找pastbin之類貼完整程式碼
12/02 22:10, 5F

12/04 03:19, 4年前 , 6F
for row in b:
12/04 03:19, 6F

12/04 03:19, 4年前 , 7F
cursor.execute(insert,row)
12/04 03:19, 7F
解決了!!謝謝 ※ 編輯: lucy35 (42.76.105.109 臺灣), 12/09/2019 01:04:53
文章代碼(AID): #1Tu_R5k9 (Python)