Gav*_*ulz 24 python sqlalchemy
我有以下查询来检索单列数据:
routes_query = select(
[schema.stop_times.c.route_number],
schema.stop_times.c.stop_id == stop_id
).distinct(schema.stop_times.c.route_number)
result = conn.execute(routes_query)
return [r['route_number'] for r in result]
Run Code Online (Sandbox Code Playgroud)
我想知道是否有一种更清晰的方法来检索返回的数据行的本机列表.
zzz*_*eek 47
将列表中的1元素元组列入列表的最简洁方法是:
result = [r[0] for r in result]
Run Code Online (Sandbox Code Playgroud)
要么:
result = [r for r, in result]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
28197 次 |
| 最近记录: |