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

MRAB python at mrabarnett.plus.com
Thu Nov 10 19:00:12 CET 2011


On 10/11/2011 14:43, Arnaud Delobelle wrote:
> On 10 November 2011 14:31, Rob Cliffe<rob.cliffe at btinternet.com>  wrote:
>> Bear in mind new and inexperienced users, or perhaps someone who doesn't
>> know Python at all but is trying to figure out what a Python program does.
>>
>>     try:
>>         ...
>>     else:
>>         ...
>>
>> is not at all intuitive.
>> If we want to allow that syntax, it would be better if 'else' were replaced
>> by something more meaningful like 'ifnoexception'.  Maybe someone can think
>> of something meaningful but more concise.
>
> "noexcept".  However, I think "else" is fine.  It's similar to how
> it's used in loops.  We have:
>
> - if / else
> - for / break / else
> - while / break / else
> - try / except / else
>
> It makes sense to me.  Also note that "else" is allowed after loops
> even if they have no "break".  So why not allow "else" after a try
> without an except?
>
The case of 'else' with the for-loops and while-loops is slightly
different because the body of the loop is repeated and you don't want
the body of the 'else' suite to be repeated.

With the 'try' statement that's not a problem.

-1



More information about the Python-ideas mailing list