I'm trying to take a list of tuples, created in python, and import them into a table in SQLite. The following code works:
conn = sqlite3.connect('emaildb4.sqlite')
cur = conn.cursor()
cur.execute('''CREATE TABLE Counts (email TEXT, count INTEGER)''')`
However, once I try to insert the dictionary, which looks like this, and is called Counts:
[('txstate.edu', 17), ('media.berkeley.edu', 56), ('vt.edu', 110), ('whitman.edu', 17), ('lancaster.ac.uk', 14), ('rsmart.com', 8), ('fhda.edu', 1), ('uct.ac.za', 96), ('unicon.net', 9), ('utoronto.ca', 1), ('loi.nl', 9), ('indiana.edu', 178), ('et.gatech.edu', 17), ('umich.edu', 491), ('gmail.com', 25), ('ucdavis.edu', 1), ('stanford.edu', 12), ('bu.edu', 14), ('caret.cam.ac.uk', 157), ('ufp.pt', 28), ('iupui.edu', 536)]
With the following code, I just get a Out[318]: <sqlite3.Cursor at 0x1b3e6500>, and no change in the SQLite table.
Code:
cur.executemany('insert into Counts (email, count) values (?,?)',Counts)
I've also tried changing the tuples to dictionaries/referencing the values by name, and looping through the list running cur.execute multiple times.
Aucun commentaire:
Enregistrer un commentaire