pyhon MySQLdb查询出来的数据设置为字典类型

import MySQLdb
import MySQLdb.cursors

cxn=MySQLdb.Connect(host='localhost',user='root',passwd='1234',db='db_name',port=3306,\
                    cursorclass=MySQLdb.cursors.DictCursor,charset="utf8")

cur=cxn.cursor()

cur.execute("select * from tablename")

for i in cur.fetchall():

    print type(i)

    break;

posted @ 2015-01-08 15:45  Beats  阅读(294)  评论(0编辑  收藏  举报