try...finally is more powerful than I thought.
Lee Harr
missive at frontiernet.net
Thu Nov 6 17:39:08 EST 2003
>> def res():
>> try:
>> a = 1
>> return
>> finally:
>> print "do I get here?"
>>
>> res()
>>
>> outputs "do I get here?"
>>
> These results might also be of interest:
>
>>>> def res():
> ... try:
> ... return 1
> ... finally:
> ... return 2
> ...
>>>> res()
> 2
>>>> def res():
> ... try:
> ... return 1
> ... finally:
> ... return
> ...
>>>> res()
>>>> def res():
> ... try:
> ... return 1
> ... finally:
> ... pass
> ...
>>>> res()
> 1
>>> def res():
... print 1
... try:
... print 2
... return 3
... print 4
... finally:
... print 5
...
>>> res()
1
2
5
3
interesting.
More information about the Python-list
mailing list