Python : How to insert a dictionary to a sqlite database?

后端 未结 5 1052
别那么骄傲
别那么骄傲 2020-12-09 05:43

I have a sqlite database with a table with following columns :

id(int) , name(text) , dob(text)

I want to insert following dictionary to it

5条回答
  •  情书的邮戳
    2020-12-09 06:07

    If, for example, c = conn.cursor(), and your dictionary is named dict and your table tablename, then you can write

    c.execute('insert into tablename values (?,?,?)', [dict['id'], dict['name'], dict['dob']])
    

    Which will insert the elements of the dictionary into the table as you require.

提交回复
热议问题