[Python-ideas] if expensive_computation() as x:

Chris Angelico rosuav at gmail.com
Tue Feb 18 01:11:09 CET 2014


On Tue, Feb 18, 2014 at 9:59 AM, Joao S. O. Bueno <jsbueno at python.org.br>
> As it is today, the operators there are just normal functions (I had
> some distant plans of fiddling with Pymacro one of these days to see
> if they could be something  different).
> So, if "expensive_computation" raises, push will never be called.

Which is also the semantics I would expect based on a purely
conceptual reading of the theory. Keep it like that :)

> x =  pop() if complex_comparison(push(expensive_operation()))  else None
> clear()
>
> (again, "complex_comparison" need just not to be that comples, just something
> that has to check the value of "expensive()" for anything other than
> boolean true/falsiness)

How about:

x = complex_comparison(push(expensive_operation())) and pop()

That'll leave you with some falsy value, rather than specifically
None, but if you know expensive_operation will return something
nonzero, that could work.

ChrisA


More information about the Python-ideas mailing list