我认为下面的情况是可能的:
attr_name = 'name'
param_value = 'John'
select(getattr(c, attr_name) for c in Customer)然而,我得到了一个错误:
attrs = ['id', 'name']
select((getattr(c, attr) if for attr in attr_name) for c in Customer)如果这可以在select语句中实现,您有什么想法吗?(也就是不要把所有东西都拉出来,然后只拉出我关心的列)
这与这里引用的用例几乎相同:
发布于 2019-06-28 09:18:46
下面的代码实现了这个功能,但它不在select语句中:
attrs = ['id', 'name']
for attr in attrs:
select(getattr(c, attr) for c in Customer)https://stackoverflow.com/questions/56716927
复制相似问题