标签 mysqldb 下的文章

Python查询Mysql时返回字典结构

aries | python | 2012-02-14
MySQLdb默认查询结果都是返回tuple,输出时候不是很方便,必须按照0,1这样读取,无意中在网上找到简单的修改方法,就是传递一个cursors.DictCursor就行。默认程序: MySQLdb默认查询结果都是返回tuple,输出时候不是很方便,必须按照0,1这样读取,无意中在网上找到简单的修改方法,就是传递一个cursors.DictCursor就行。默认程序:  import MySQLdbdb = MySQLdb.connect(host = ´localhost´, user = ´root´, passwd = ´123456´, db = ´test´)cursor = db.cursor()cursor.execute(´select * from table´)rs = cursor.fetchall()print rs [阅读全文]
ė 6 0条评论 0
Ɣ回顶部