python - pymysql fetchall() 结果作为字典?

标签 python mysql

有没有办法使用 pymysql 从 fetchall() 中获取结果作为字典?

最佳答案

PyMySQL 包含一个 DictCursor。它做我认为你想要的。使用方法如下:

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

关于python - pymysql fetchall() 结果作为字典?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4940670/

相关文章:

python - 属性错误 : 'Foo' object has no attribute 'max'

python - python中的'in'关键字 - 同一性还是平等?

Python C 扩展 - 为什么可调用 C 函数必须接受参数并返回 PyObject *

jquery - 删除 phalcon 中的多个选定行

java - 从数据库查询重新格式化 json

mysql - sql in 运算符,每个元素都有限制和偏移量

javascript - Flask Jinja2 模板语法与 AngularJS 冲突(jinja2.exceptions.UndefinedError :)

serialization - python : How to save object state and reuse it

php - 数据表搜索框不起作用

mysql - 如何在mysql中显示ID