[Tutor] sqlite3 lists to database conversion/ using python variables in sqlite3

amit sethi amit.pureenergy at gmail.com
Wed Nov 19 12:18:34 CET 2008

Hi , i am trying to learn python and this is my first time with any
databases . I am using sqlite3 to create a database of my music files and
metadata tags so here is what i wanted to do . Two list one of the
attributes and one of their values ,how do i put it in the database.Here is
a simple code i think should work but isn't?
>>> import sqlite3
>>> conn=sqlite3.connect('/tmp/example2')
>>> c = conn.cursor()

>>> list1=['hello','hi']
>>> list2=['a','b']
>>>c.execute('''create table ABC(hello text,hi text)''')
>>> list1_value= ",".join(list1)
>>> list2_value= ",".join(list2)
>>> c.execute('''insert into ABC (%s) values
This is the error it generates
sqlite3.OperationalError: near "%": syntax error
why doesn't this work . Can someone please explain

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081119/8cc90bdb/attachment.htm>

More information about the Tutor mailing list