pymysql fetchall()结果作为字典? [英] pymysql fetchall() results as dictionary?
本文介绍了pymysql fetchall()结果作为字典?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有什么办法可以使用pymysql从fetchall()作为字典获取结果?
Is there any way to get the results from a fetchall() as a dictionary using pymysql?
推荐答案
PyMySQL包含DictCursor
.它确实满足我的要求.使用方法如下:
PyMySQL includes a DictCursor
. It does what I think you want. Here's how to use it:
import pymysql
connection = pymysql.connect(db="test")
cursor = connection.cursor(pymysql.cursors.DictCursor)
cursor.execute("SELECT ...")
https://github.com/PyMySQL/PyMySQL/blob/master/pymysql/tests/test_DictCursor.py
这篇关于pymysql fetchall()结果作为字典?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文