Python 3.x Sqlalchemy进程查询和生成CSV
我正在尝试循环sqlalchemy查询的结果,就像使用PHP的一样Python 3.x Sqlalchemy进程查询和生成CSV,python-3.x,sqlalchemy,Python 3.x,Sqlalchemy,我正在尝试循环sqlalchemy查询的结果,就像使用PHP的一样 while($query->fetch_assoc()){} 我尝试过添加[qry中x的x],但似乎不起作用 def on_get(self, req, resp, id): """Generates CSV for log.""" qry = db.Session.query(db.Log, db.Location).\ filter(db.Log.location_i
while($query->fetch_assoc()){}
我尝试过添加[qry中x的x]
,但似乎不起作用
def on_get(self, req, resp, id):
"""Generates CSV for log."""
qry = db.Session.query(db.Log, db.Location).\
filter(db.Log.location_id == db.Location.id).\
filter(db.Log.location_id == id)
qry = helpers.filter_between_dates(qry, req, db.Log.log_time)
# helpers.write_csv_from_query(resp, qry, falcon.HTTP_200, "a b c")
resp.status = falcon.HTTP_200
resp.content_type = 'text/csv'
resp.set_header('Content-disposition', 'attachment; filename=test.csv')
resp.body = ([x for x in qry])
我试图通过RESTAPI将要生成的数据返回到CSV中。我不确定这是否是最好的方法,请告诉我这是正确的方法还是有正确的方法
谢谢第二次出现时,请参见覆盖
qry
。