Passing expressions to functions?

前端 未结 6 467

I\'m not quite sure what I mean here, so please bear with me..

In SQLAlchemy, it appears I\'m supposed to pass an expression to filter() in certain cases. When I try to

6条回答
  •  星月不相逢
    2021-02-01 20:33

    An even more pythonic variant of Nelson's solution is to use the operator functions from the operator module in the standard library; there is no need to create your own lambdas.

    >>> from operator import eq
    >>> def magic(left, op, right):
    ...   return op(left, right)
    ... 
    >>> magic(5, eq, 5)
    True
    

提交回复
热议问题