【发布时间】:2021-06-16 14:53:00
【问题描述】:
试图捡起一些蟒蛇。我现在对它很陌生。
我创建了下面的代码,但它返回一个错误。
我能够在创建第二列并将多个值写入数据库时使其工作,但单个值似乎不起作用。可能是一个列表,元组的东西,但无法弄清楚到底是什么。
错误:
Traceback (most recent call last):
File "test.py", line 15, in <module>
cursor.executemany("INSERT INTO combination VALUES (?)", combination)
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 2 supplied.
代码:
import sqlite3
conn = sqlite3.connect("combinations.db")
cursor = conn.cursor()
cursor.execute(r"create table if not exists combination (string text)")
combination = []
chars = "abcd"
for char1 in chars:
for char2 in chars:
combination.append((char1+char2))
cursor.executemany("INSERT INTO combination VALUES (?)", combination)
conn.commit()
【问题讨论】:
标签: python binding executemany