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

Chris Angelico rosuav at gmail.com
Fri Feb 14 07:51:02 CET 2014


On Fri, Feb 14, 2014 at 5:49 PM, Michele Lacchia
<michelelacchia at gmail.com> wrote:
> You could gather all the functions in a list and then iterate and break when
> needed:
>
> for func in [f1, f2, f3, f4]:
>     x = func()
>     if x:
>         # bla bla
>         break
>
> Sorry for the indentation if it's not right, I'm writing from my phone.

The indentation's fine, but this still assumes that the 'if x' block
in each case is the same.

ChrisA


More information about the Python-ideas mailing list