[Python-ideas] try-else without except or finally

Mathias Panzenböck grosser.meister.morti at gmx.net
Mon Nov 14 22:37:47 CET 2011


On 11/10/2011 02:28 PM, Steven D'Aprano wrote:
>
> try:
> ...
> else:
> # Run the else block unless we exit the try block with an exception.
> ...
> finally:
> ...
>

To me this would intuitively read as:
Do the try block if you can, else (if you can't) do the else block.
And you can't if an exception is raised.

This is exactly the opposite of the intended meaning. The except is needed because the else refers 
to it. Without the except the else would refer to the try and one would expect behaviour as with an 
"except:" block.

Also when ever would you need an else block without an except block? Just append it to the try block 
and you get the same behaviour.

As for the not immediately intuitive meaning of the finally block: Yes, maybe "ensure" would have 
been better. But it's to late for that to change.

-1 from me

	-panzi



More information about the Python-ideas mailing list