python mysql to dict

cursor.execute(sql)
            rows = cursor.fetchall()
            result_list = []
            columns = [desc[0] for desc in cursor.description]  # get column names
            for row in rows:
                result_list.append(dict(zip(columns, row)))
            data['result'] = result_list
posted @ 2024-01-23 16:38  vx_guanchaoguo0  阅读(5)  评论(0编辑  收藏  举报