cursor.fetchall()返回的是元组,不包含字段名,但是python的DBAPI标准里面规定每一次的查询必须要包含字段信息等。
获取字典结果
sql = "select * from table"
cursor = conn.cursor()
cursor.execute(sql)
column_names = [ col[0] for col in cursor.description ]
dict_res = [
dict( zip(column_names, row))
for row in cursor.fetchall()
]