Why no 'elif' in try/except?

Jonathan Gardner gardner at cardomain.com
Sat Jun 9 23:52:34 EDT 2001


Carsten Gaebler wrote:

> Hi there!
> 
> How about adding an 'elif' to try/except? I.e.:
> 
> try:
>   res = dosomethingnasty()
> except:
>   complain()
> elif res == 1:
>   behappy()
> 
> instead of
> 
> try:
>   res = dosomethingnasty()
> except:
>   complain()
> else:
>   if res == 1:
>     behappy()
> 
> Any opinions?
> 

Wouldn't an 'eltry' (= "else: try:" ) make more sense?

try:
    something
except:
    error on something
eltry:
    something else
except:
    error on something else
else:
    everything working great

Which is the same as:

try:
    something
except:
    error on something
else:
    try:
        something else
    except:
        error on something else
    else:
        everything working great

The first just looks better.

Thinking-around-the-else-ly yours,
Jonathan



More information about the Python-list mailing list