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

Arnaud Delobelle arnodel at gmail.com
Thu Nov 10 15:43:18 CET 2011


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?

-- 
Arnaud



More information about the Python-ideas mailing list