我一直在尝试创建一个数据库,我的表的列名来自一个列表:
import sqlite3
L = ["Nom","Age","Taille"]
list2 = ["Karl", "11", "185"]
M = []
R = 0
con = sqlite3.connect(":memory:")
con.execute("CREATE TABLE master ("+",".join(L)+")")
然后要么:
for e in L:
R += 1
con.execute("INSERT INTO master("+",".join(L)+") VALUES (?,?,?)",list2[R-1])
或者
for e in L:
R += 1
con.execute("INSERT INTO master(e) VALUES (?)",list2[R-1])
或者
listX=[list2[0],list2[1],list2[3])
con.executemany("INSERT INTO master ("+",".join(L)+") VALUES ("+",".join(M)+")", (listX))
拉丁的传说
相关分类