我正在尝试从与此类似的循环中插入数据。
import sqlite3
conn = sqlite3.connect('database.db')
c = conn.cursor()
words = ["apple", "banana", "cherry"]
for word in words:
c.execute("insert into Words (word), values (?)",(word))
print(word)
conn.commit
c.close()
conn.close()
预期结果与此类似:
我收到一个错误。但我不确定如何正确格式化此代码。
错误:
Traceback (most recent call last):
File "file.py", line 7, in <module>
c.execute("insert into Words (word), values (?)",(word))
sqlite3.OperationalError: near ",": syntax error