【发布时间】:2015-08-21 10:24:00
【问题描述】:
我不得不将 python 脚本从 python2 重写为 python 3 来解决我最简单的编码问题。我不得不从 mysqldb 转移到似乎使用相同语法的 pymysql。我访问了 pymysql 的 github[1] 站点并通过以下示例注意到,当查询结果是一个元素时,它返回一个 JSON 对象,但当它返回多个时,它返回一个列表。
总是返回一个包含 0、1 或任何数量元素的列表不是更一致吗?为什么这样做?
注意:为了避免在 pymysql 中出现这种行为,只需从以下位置删除 cursorclass 参数:
# Connect to the database
connection = pymysql.connect(host='localhost',user='user',
passwd='passwd', db='db', charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
【问题讨论】: