Sunday, September 14, 2014

Python: return a dictionary from MySQLdb query

By default MySQLdb library in Python only returns an array of values in the order you retrieve them. But you can return an dictionary by changing the cursor type to: MySQLdb.cursors.DictCursor:

cursor = conn.cursor(cursorclass=MySQLdb.cursors.DictCursor)

Have a try and have fun.

No comments: