码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2015-01-08 17:00:23      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:

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;

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

标签:

原文地址:http://www.cnblogs.com/wushirenfei/p/4211178.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!