【发布时间】:2020-03-25 05:45:23
【问题描述】:
我有 3 个这样的列表:
list_model = [2000, 2010, 2020, 1998, 2016]
list_worked = [1200, 0, 45000, 123000]
list_price = [920000, 123000, 12, 6500]
我想将它们插入到这样描述的 MySQL 数据库中:
+---------+------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+------+------+-----+---------+-------+
| model | int | YES | | NULL | |
| worked | int | YES | | NULL | |
| price | int | YES | | NULL | |
+---------+------+------+-----+---------+-------+
我尝试使用
cursor = mydb.cursor()
cursor.execute ("INSERT INTO l90 VALUES (%i, %i, %i)" % (list_model, list_karkard, list_gheymat ))
mydb.commit()
mydb.close()
但它显示“TypeError: %i format: a number is required, not list” 我不知道该怎么办,谁能帮帮我?
【问题讨论】:
-
您是要插入 5*4*4=80 条记录(所有可能的组合),还是要插入 5 条位置匹配的记录(第 5 条记录在
worked和price因为列表大小不同)?