我正在尝试在数据库中插入列表列表,但出现此错误“cursor.execute('INSERT INTO Test VALUES(?, ?, ?)',list2) sqlite3.ProgrammingError: 提供的绑定数量不正确。当前语句使用 3,并且提供了 200 个。” 在我的列表列表中有 201 个列表import sqlite3import csvimport pandas as pddef Load(): list1 = [] comparar = [] conexion = sqlite3.connect("Pruebas") cursor = conexion.cursor() cursor.execute('CREATE TABLE IF NOT EXISTS Test ( "id" INT NOT NULL , "User" TEXT NOT NULL , "Followed" INT NOT NULL , PRIMARY KEY (id))') cursor.execute("SELECT * FROM Test") list1 = cursor.fetchall() #print(data) data = pd.read_csv(r'J:\\Proyectos y Trabajos\\Python\\Bot Instagram Follow\\Terminado BR\\Test.csv',delimiter=';') tuples = [tuple(x) for x in data.values] for i in tuples: if i not in list1: list1.append(i) list2 = [list(elem) for elem in list1] cursor.execute("DELETE FROM Test") conexion.commit() cursor.execute('INSERT INTO Test VALUES(?, ?, ?)',list2) conexion.commit() conexion.close()Load()
1 回答
SMILET
TA贡献1796条经验 获得超4个赞
迭代list2并对每个子列表中的值执行插入:
for sublist in list2:
cursor.execute('INSERT INTO Test VALUES(?, ?, ?)', sublist)
connexion.commit()
添加回答
举报
0/150
提交
取消