0
這是我的代碼:Python的sqlite3的和字符串格式化 - 錯誤
title = "Importunate Widow"
conn = sqlite3.connect('parable.sqlite')
c = conn.cursor()
sqlite3.enable_callback_tracebacks(True)
c.executescript("""
CREATE TABLE IF NOT EXISTS _index(
title text NOT NULL,
context text NOT NULL
);
CREATE TABLE IF NOT EXISTS {}(
value int NOT NULL,
number int NOT NULL,
question text NOT NULL,
choice1 text,
choice2 text,
choice3 text,
choice4 text,
answer text NOT NULL,
explanation text,
see text
)""".format(title))
c.executemany('INSERT INTO _index(title,context) VALUES(?,?)', index)
c.executemany('INSERT INTO {}(value,number,question,choice1,choice2,choice3,choice4,answer,explanation,see) VALUES(?,?,?,?,?,?,?,?,?,?)'.format(title), quiz)
conn.commit()
conn.close()
這給了我:
OperationalError Traceback (most recent call last)
/home/user/Hobby/Quiz/quiz_sqlite.py in <module>()
sqlite3.enable_callback_tracebacks(True)
87
---> 88 c.executescript("""CREATE TABLE IF NOT EXISTS _index(title text NOT NULL,context text NOT NULL);CREATE TABLE IF NOT EXISTS {}(value int NOT NULL,number int NOT NULL,question text NOT NULL,choice1 text,choice2 text,choice3 text,choice4 text,answer text NOT NULL,explanation text,check text)""".format(title))
89
90 c.executemany('INSERT INTO _index(title,context) VALUES(?,?)', index)
OperationalError: near "Widow": syntax error
我基本上遍歷多個文件,並插入數據文件後,命名錶。我搜索了互聯網,並沒有出現任何東西。
我的嘗試:
- 試過之後
see text
- 試圖改變列的名稱
see
到refer
無添加;
的)
前"""
,
後這有助於! 代碼中的語法錯誤是什麼?