[Python-ideas] for/else statements considered harmful
Alice Bevan–McGregor
alice at gothcandy.com
Thu Jun 7 17:52:10 CEST 2012
On 2012-06-07 15:30:11 +0000, Mike Meyer said:
> Calling it "wrap-up processing" seems likely to cause people to think
> about it as meaning "finally". But if the else clause is not executed
> if the except clause is (as done by try/except/else), then there's no
> longer an easy way to describe it.
>
> It seems like adding an except would change the conditions under which
> the else clause is executed (unlike try/except/else), as otherwise
> there's no easy way capture the current behavior, where else is
> executed whenever there are no chunks left to process. But that kind
> of things seems like a way to introduce bugs.
Well, how about:
for <var> in <iterable>:
pass # process each <var>
except: # no arguments!
pass # nothing to process
else:
pass # fell through
finally:
pass # regardless of break/fallthrough/empty
Now for loops perfectly match try/except/else/finally! >:D (Like
exception handling, finally would be called even with an inner return
from any of the prior sections.)
— Alice.
More information about the Python-ideas
mailing list