I'd like to insert the values of a Python dictionary into a SQLite table, where the key values are equal to existing SQLite column values.
in pseudocode: cursor.execute("INSERT INTO table(library_keys) VALUES(library_values)")
I could not get it to work inserting library_keys and library_values as variables pointing to lists. As I couldn't find any similar examples on-line I assume this is not possible.
I have found an answer that satisfies when the number of keys/columns is fixed: stackoverflow: INSERT dictionary sqlite3 (python). I have however libraries of varying size (up to 30 keys) which I'd like to INSERT INTO the table. I could use IF ELIF to match the number of keys for each library to be inserted, but that would take 29 ELIF lines. That somehow doesn't feel Zen.
Does anyone know a better way of doing this?
Aucun commentaire:
Enregistrer un commentaire