I will bring below a function code snippet which I can't make to work correct way.
def upload_csv():
conn = sqlite3.connect("data.db")
cursor = conn.cursor()
#as far as tkFileDialog returns absolute path to file, we have to slice from last slash till the end
filename = fn[fn.rfind("/")+1:]
cursor.execute("CREATE TABLE IF NOT EXISTS {0}('MSISDN' INTEGER PRIMARY KEY, 'IMEI' TEXT, 'TAC' INTEGER );".format(filename))
reader = csv.reader(open(fn,'r'))
for row in reader:
to_db = [unicode(row[0]),unicode(row[1]),unicode(int(row[2][0:8]))]
print to_db
cursor.execute("INSERT INTO data.{0} (MSISDN,IMEI,TAC) VALUES (?,?,?);".__format__(filename), to_db)
conn.commit()
I receive an Operational error: OperationalError: unknown database May2015
Aucun commentaire:
Enregistrer un commentaire