我想通过连接多个列来创建标量。如果列列表是静态的,我可以这样做:
sa.select([table.c.col1 + table.c.col2 + 'done']).as_scalar()
但是,我的清单是动态的。没有使用eval()
有没有办法做到这一点?
你几乎从不需要eval()
- 它可以是evil。在这种情况下,只需在列/表达式列表中使用functools.reduce()
:
sa.select([reduce(operator.add, [table.c.col1, table.c.col2, 'done'])])