Python: use mysqldb to import a MySQL table as a dictionary?

MySQLdb has a separate cursor class for this, the DictCursor. You can pass the cursor class you want to use to MySQLdb.connect():

import MySQLdb.cursors
MySQLdb.connect(host="...", cursorclass=MySQLdb.cursors.DictCursor)

Leave a Comment