In the code below row is a tuple of 200 elements (numbers) and listOfVars is a tuple of 200 strings that are variable names in the testTable. tupleForm is a list of tuples, 200 elements in each tuple.
The following code does not work. It returns a syntax error:
for row in tupleForm:
cmd = '''INSERT INTO testTable listOfVars values row'''
cur.execute(cmd)
However, the following works fine. Can someone explain why? I am finding sqlite so non-intuitive.
for row in tupleForm:
cmd = '''INSERT INTO testTable %s values %s'''%(listOfVars, row)
cur.execute(cmd)
Thanks for your help.
listOfVarsorrowmean...print(cmd)after yourcmd = ...assigments, and you'll see the difference in the 2. This isn't really a sqlite thing, it's simply a Python string formatting question. The best way to accomplish what you're trying to do is to apply Adam Bernier's answer.