2016-02-28 66 views
0

我一直在收到這個錯誤,並試圖瞭解我做錯了幾個小時。我過去曾多次使用此模板成功導入sqlite3。Python sqlite3值錯誤

def TestImport(): 
    con = sqlite3.connect("test.db") 
    con.execute("CREATE TABLE IF NOT EXISTS TestTable(ColA,ColB)") 
    data=[('x','y')] 
    stmt = "INSERT INTO TestTable VALUES(?,?)" 
    con.execute(data,stmt) 
    con.commit() 
    con.close() 

然而,這一次,我收到此錯誤:

ValueError: operation parameter must be str or unicode 

這裏

con.execute(data,stmt) 

回答

1

應該

con.execute(stmt, data[0])