古丁高手 发表于 2016-09-01 15:08

有什么好的方法处理数据库返回的查询结果fetchall?


数据库返回来的查询是元组,如何格式化处理好?特别是日期方面

Hadron74 发表于 2016-09-01 15:28

放在pandas里。
http://stackoverflow.com/questions/12047193/how-to-convert-sql-query-result-to-pandas-data-structure

ghostwwl 发表于 2016-09-02 12:58

本帖最后由 ghostwwl 于 2016-09-02 12:59 编辑

我以前好像是这么干的

get_fields = ('id', 'name', 'title');
sql= 'select %s from aaa' % (','.join(get_fields)

结果:
r = []
for item in xxx:
    result = dict(zip(get_fields), item))
    r.append(result)
   

古丁高手 发表于 2016-09-02 15:50

我这样干了,结果也是我想要的。回复 3# ghostwwl


页: [1]
查看完整版本: 有什么好的方法处理数据库返回的查询结果fetchall?