i have data structure i'm iterating through:
somelist = [[id, vara, varb, datec, vard],[id2, vara2, varb2, datec2, vard2]...] the datecx variables of form:
"2013-07-15t13:58:55z" i've used sqlite library create sqlite database:
import sqlite3 lite con = lite.connect('test.db') con: cur = con.cursor() cur.execute("create table test(columnid int, columna text, columnb text, columnc datetime, column d text)") i'm iterating through somelist:
for list in somelist: tempid = list[0] tempa = list[1] tempb = list[2] tempdatec = list[3] tempd = list[4] for date field, i've been leveraging strptime function in time library parse in python:
tempdatec = time.strptime(tempdatec, "%y-%m-%dt%h:%m:%sz") which results in tuple i'm expecting.
i tried update test database:
allvalues = (tempid, tempa, tempb, tempdatec, tempd) cur.execute("insert test values(?, ?, ?, ?, ?)", allvalues) but i'm getting following error:
sqlite3.interfaceerror: error binding parameter 3 - unsupported type. is there else have convert tuple i've created can inserted sql db?
okay, figured out.
you have to
import time import datetime and then, rather than
tempdatec = time.strptime(tempdatec, "%y-%m-%dt%h:%m:%sz") you need parse date few functions:
tempdatec = datetime.datetime.fromtimestamp(time.mktime(time.strptime(tempdatec, "%y-%m-%dt%h:%m:%sz")))
Comments
Post a Comment