Python - Returning the output as a dictionary - MySQL -


i have coded class handle mysql connecting using external modules when data want returned like:

{ 'id': '1', 'username': 'test'} 

it's returned:

(1, u'test') 

the code use is:

def executequery(self, query):     if(self.mysqlsuccess):         cursor = self.cnx.cursor()         cursor.execute(query)         row in cursor:             print row executequery('select * `users`') 

you can use dictcursor when initializing connection mysql.

import mysqldb.cursors  cnx = mysqldb.connect(user='joe', passwd='password', db='dbname',                       cursorclass=mysqldb.cursors.dictcursor) 

if using diff mysql package check docs dictcursor.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -