gpt4 book ai didi

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

转载 作者:IT老高 更新时间:2023-10-28 12:58:19 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com