Output pyodbc cursor results as python dictionary

后端 未结 8 1619
孤独总比滥情好
孤独总比滥情好 2020-11-29 18:37

How do I serialize pyodbc cursor output (from .fetchone, .fetchmany or .fetchall) as a Python dictionary?

I\'m using bottlepy

8条回答
  •  醉酒成梦
    2020-11-29 19:19

    For situations where the cursor is not available - for example, when the rows have been returned by some function call or inner method, you can still create a dictionary representation by using row.cursor_description

    def row_to_dict(row):
        return dict(zip([t[0] for t in row.cursor_description], row))
    

提交回复
热议问题