Why no 'elif' in try/except?

Ype Kingma ykingma at accessforall.nl
Sun Jun 3 08:13:52 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?

The 'else:' in 'try: except: else:' should have been called 'normally:'.

Regards,

Ype


P.S. A possible cause of this problem is that sheep normally don't fly:

try:
  sheep.fly()
except:
  sheep.fell()
normally:
  ???

P.P.S. Perhaps this code be preceeded by "while 1:" to make it more clear.

-- 
email at xs4all.nl



More information about the Python-list mailing list