mysql查询数据返回touple改为字典的方法

conn = MySQLdb.connect(host='ip',user='root',passwd='123456',db="dbname",charset="utf8")  

cursor = self.conn.cursor(cursorclass=MySQLdb.cursors.DictCursor)    #这行重要

 

有很多是说把cursorclass=MySQLdb.cursors.DictCursor 这行代码加在connect参数里,但在python 2.7上是会报错的。

原文地址:https://www.cnblogs.com/xiaobaichuangtianxia/p/5482504.html