Alex Rivera | Logout

Passing expressions to functions

Asked 2009-07-26T18:26:21.237
25

In SQLAlchemy, it appears I'm supposed to pass an expression to filter() in certain cases. When I try to implement something like this myself, I end up with:

>>> def someFunc(value):
...     print(value)

>>> someFunc(5 == 5)
True

How do I get the values passed to == from inside the function?

I'm trying to achieve something like this

 >>> def magic(left, op, right):
 ...    print(left + " " + op + " " + right)

 >>> magic(5 == 5)
 5 == 5

What about if one of the parameters was an object?

Edit
Report

1 Answer

0

Short answer: You can't. The result of the expression evaluation is passed to the function rather than the expression itself.

answered 2009-07-26T18:31:11.663

Your Answer