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

Steven D'Aprano steve at pearwood.info
Fri Feb 14 21:48:20 CET 2014


On Fri, Feb 14, 2014 at 05:18:55AM -0500, Terry Reedy wrote:

> I do not really understand the fear of indents that would cause one to 
> repeat calculations rather than write the actual logic.
> 
>     x = expensive_computation_0():
>     if x:
>         # Do something with x...
>     else:
>         x = expensive_computation_1()
>         if x:
>             # Do something with x...

That's really not very nice looking. It's okay with one or two levels, 
three at the most, but avoiding that sort of thing is why we have elif 
in the first place. So I wouldn't call it a *fear* of indents, more an 
dislike of excessive indentation.



-- 
Steven


More information about the Python-ideas mailing list