I have a dict like this:
{
'05_23': '[L]',
'05_22': '9:39',
'05_21': '9:37',
'05_20': '9:34',
'05_27': '14:41'
}
I take the keys and values from it and create lists:
keys = list(d.keys())
print keys
['05_23', '05_22', '05_21', '05_20', '05_27']
values = list(d.values())
print values
['[L]', '9:39', '9:37', '9:34', '14:41']
And then I construct this SQL query with it:
c.execute("INSERT INTO table {} VALUES {}".format(tuple(keys), tuple(values)))
Which results in the following error:
c.execute("INSERT INTO table {} VALUES {}".format(tuple(keys), tuple(values)))
sqlite3.OperationalError: near "table": syntax error
And I can't figure out how to make it work.
tableis a SQL keyword. You want the table name there.INSERT INTO table_name (column1,column2,column3,...) VALUES (value1,value2,value3,...);you need to replace table_name with the name of your tablec.execute("INSERT INTO table_name (X) VALUES (:X)", d)