Inserting multiple dictionary objects into a MySQL database using python and MySQLdb
I have been struggling with this for hours and I feel like crying now as I'm unable to fathom out what is happening. Here is a simplified version of my data: mydata = [ { 'id': 123, 'thing': 'ghi', 'value': 1 }, { 'id': 456, 'thing': 'xyz', 'value': 0 } ] This is the code I have: import MySQLdb as mdb con = None con = mdb.connect('localhost', 'testing', 'anothervalue', 'andanother'); cur = con.cursor() sql = "INSERT INTO `tablename` ( `id`, `thing`, `value` ) VALUES ( %(id)s, %(thing)s, %(value)s )" cur.executemany( sql, ( mine for mine in mydata ) ) con.close() What I expected to happen was