[python] using try: finally: except

Peter Hansen peter at engcorp.com
Sat Jun 19 03:33:18 CEST 2004


OKB (not okblacke) wrote:

> Carl Banks wrote:
> 
>>The right way is:
>>
>>    try:
>>        try:
>>            x = 'hello'
>>        except:
>>            print "oops"
>>    finally:
>>        y = 'world'
>>        print x," ",y
> 
>     	I seem to recall reading somewhere that this was a cop-out for some 
> implementation reason.  Is there any word on when or if it's going to be 
> remedied?  It seems unbearably ugly and unintuitive; one of the most 
> irritating Python warts.

I recall differently.  I recall reading several times that since
it is completely ambiguous what the programmer meant if both are
specified together, Guido deliberately kept them separate so that
one had to be very explicit about whether the finally was inside
or outside the except.  The behaviour of the code is quite different
depending on the order...

-Peter



More information about the Python-list mailing list