我有下面显示的下一个结构,我在
后得到它cur.execute('SELECT id, array_agg(row(id, name)) as list_names FROM bookie GROUP BY id')
result = cur.fetchall()
result ['list_names']返回
"{"(514,\"Fortuna CZ\")","(514,\"Fortuna CZ\")","(513,\"Tipsport CZ\")","(513,\"Tipsport CZ\")","(,)","(,)"}"
下面的几个问题:
如何将result ['list_names']正确转换为简单列表或元组,如下所示?
[(514,'Fortuna CZ'),(513,'Tipsport')..)
答案 0 :(得分:4)
尝试通过添加条件来更改查询以排除空字段:
WHERE name IS NOT NULL
答案 1 :(得分:0)
尝试
newresult = [x表示结果为x,如果x!='']