有没有办法使用 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/