python - SyntaxError: invalid syntax on commit -
python - SyntaxError: invalid syntax on commit -
import sqlite3 import numpy conn = sqlite3.connect('lotto.db') cur = conn.cursor() def fun(a,b,c,d,e,f): list = [a, b, c ,d, e, f] print(list) homecoming numpy.mean(list) numbers = cur.execute("select * combinations6") numbers.fetchall() row in numbers: cur.execute("update combinations6 id = ? set average = ?", (row, fun(row[0],row[1],row[2],row[3],row[4],row[5])) conn.commit() conn.close()
having problem getting iterate on each row getting syntax errors , when run calculates average of first row , inputs rows of database
what doing wrong iterate on each row , calculate average , input database?
pretty new python in advance help.
the problem isn't in python, it's sql syntax. where
clause comes after set
:
cur.execute("update combinations6 set average = ? id = ?", (fun(row[0],row[1],row[2],row[3],row[4],row[5]), row)
don't forget swap order of substitution parameters match this.
also, you're using row
parameter id = ?
, isn't right. can't set whole list parameter, has specific element of list, e.g. row[6]
. don't know actual position of id column in table, don't know right index is.
you can entire thing single query:
update combinations6 set average = (col1 + col2 + col3 + col4 + col5 + col6)/5
replace col1
, etc. actual names of columns you're computing average of.
python sqlite
Comments
Post a Comment