Python,MySQL和SELECT输出到带有键列名的字典 [英] Python, MySQL and SELECT output to dictionary with column names for keys

查看:289
本文介绍了Python,MySQL和SELECT输出到带有键列名的字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MySQL表,正在Python中执行SELECT语句.

I have a MySQL table on which I'm executing SELECT statements within Python.

Python MySQLdb API之外是否有任何东西可以通过游标输出一个字典数组,其键为列名(值是返回行中的值)?

Is there anything out of the Python MySQLdb API that will, via the cursor, output an array of dictionaries whose keys are the column names (and values are those in the returned rows)?

推荐答案

请使用字典光标:

cursor = conn.cursor (MySQLdb.cursors.DictCursor)

这篇关于Python,MySQL和SELECT输出到带有键列名的字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆