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


Anyone know how I can use mysqldb to turn on mysql table, with multiple rows In a list of dictionary objects in Python?

I mean that with a set of MySQL rows, columns 'A', 'B', and 'C', in a python object that looks like this:

  data = [['A': 'A', 'B': (2, 4), 'C': 3.0}, {'A': 'Q', 'B': (1, 4) , 'C': 5.0}, {'A': 'T', 'B': (2, 8), 'C': 6.1}]  

thanks :)

For this there is a separate cursor class of MySQLdb, DictCursor you can pass the cursor class, which you can call MySQLdb Want to use .connect ():

  MySQLdb.cursors MySQLdb.connect (host = '...', cursorclass = MySQLdb.cursors.Di CtCursor)  

Comments

Popular posts from this blog

.net - C# List<T>.Find(x=>x.Rectangle.Contains(Point)) FAIL -

iphone - Smoothing a rounded stroke in Core Graphics -

c++ - QtQuick: QQmlApplicationEngine failed to load component qrc:/main.qml:23 Invalid attached object assignment -