mysql - Python: Inserting row into database with formatting -


i'm trying insert row table i've set in database.

my code:

cursor.execute("""insert scan (prefix, code_id, answer, station) values(%s, %s, %s, %s, timestamp, comport)""",[(prefix, code_id, answer, station)]) 

i'm getting error saying doesn't in "[]".

i don't understand how "%s" works. i've tried many examples , have failed me.

i got example http://mysql-python.sourceforge.net/mysqldb.html

why have parameters inside 2 sets of brackets? second argument should sequence containing 4 items, match 4 %ss in query. instead, have given list containing 1 item: item sequence 4 items in it.

instead, try:

cursor.execute("""insert scan (prefix, code_id, answer, station) values(%s, %s, %s, %s, timestamp, comport)""",(prefix, code_id, answer, station)) 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -