-1
繼關於從Python中的CSV文件的sqlite3數據庫的人口一前一後,我有完全用代碼編寫的,但滾滾而來了:回溯(最近通話最後一個):從csv填充sqlite3數據庫:圍繞'?'的語法錯誤
File "Z:/KS4/Computer Science/OCR corsework/Task 1 Database/populate.py", line 10, in <module>
cursor.execute(query, data)
sqlite3.OperationalError: near "?": syntax error
這是代碼:
import csv, sqlite3
connection = sqlite3.connect("TutorGroup.db")
with open ('studentsEmail-master.csv', 'r') as f:
r = csv.reader(f)
data = next(r)
query = 'insert into dbo.students ({0})'
query = query.format(','.join('?' * len(data)))
cursor = connection.cursor()
cursor.execute(query, data)
for data in reader:
cursor.execute(query, data)
cursor.commit()
查詢的內容是什麼?你能打印出來嗎? –
你缺少*'values' *關鍵字。 –