[Python-ideas] try-else without except or finally
Ethan Furman
ethan at stoneleaf.us
Thu Nov 10 20:05:09 CET 2011
Steven D'Aprano wrote:
> Yuval Greenfield wrote:
>
>> "Try...else..." doesn't make any sense without the except jn my eyes. The
>> "else" has to conjugate something.
>
>
> We already have while...else and for...else blocks in Python. The
> principle is the same:
>
>
> while condition():
> ...
> else:
> # Run the else block unless we exit the while block with a break.
> ...
>
>
> try:
> ...
> else:
> # Run the else block unless we exit the try block with an exception.
> ...
> finally:
> ...
-1 to skipping the except
while/else and for/else are more along the lines of 'when condition is
False, run the else suite -- how would you have a false condition for
the try? You don't, you have a false condition for the except.
~Ethan~
More information about the Python-ideas
mailing list