python psycopg2 查询结果返回字典类型

    def select(self, sql, parm=None):
        self.cr.execute(sql, parm)
        list_header = [row[0] for row in self.cr.description]
        list_result = [[str(item) for item in row] for row in self.cr.fetchall()]
        res = [dict(zip(list_header, row)) for row in list_result]
        # print(list_header)
        # pprint(list_result)
        # pprint(res)
        return res

posted @ 2020-12-25 10:37  那时一个人  阅读(1220)  评论(0编辑  收藏  举报