What is the most effective way of Inserting Python dictionaries / lists into SQL database?
If your data is structured like that, it would lend itself more towards a document orientated database (Mongo/Couch etc...)
You can get away with something like this... I think using
repr is being a little too clever...
insert_sql = 'INSERT INTO conditions_bratislava(%s) values(%s)'cols = ', '.join(somedict)vals = ', '.join('?' * len(somedict)) # or whatever qparam is requiredto_execute = insert_sql % (cols, vals)some_cursor.execute(to_execute, somedict.values())
On a side note:
value_type = type(value)if value_type is unicode:
Should be written as:
if isinstance(value, unicode):