Search code examples
pythonsqliteexecutemany

python 2.4.3 sqlite executemany syntax


I am stuck using python 2.4.3 and the sqlite module issued with that distribution.

How can i run the executemany command in this environment? The more modern syntax seems to have an issue.

import sqlite as sql
conn = sql.connect('test.db')
c = conn.cursor()
c.execute('''create table test(item text)''')
list = ['apple', 'orange', 'banana']

c.executemany('''insert into test values(?)''', list)

Python 2.4.3 is quite old I guess and I can't find any docs, and I have no assoicated doc string associated with the executemany function.

I appreaciate the help.


Solution

  • You should use %s instead of ?:

    import sqlite as sql
    conn = sql.connect('test.db')
    c = conn.cursor()
    c.execute('''create table test(item text)''')
    list = ['apple', 'orange', 'banana']
    c.executemany('''insert into test values(%s)''', list)