try...finally is more powerful than I thought.
Peter Hansen
peter at engcorp.com
Thu Nov 6 23:29:45 EST 2003
Lee Harr wrote:
>
> >>> def res():
> ... print 1
> ... try:
> ... print 2
> ... return 3
> ... print 4
> ... finally:
> ... print 5
> ...
> >>> res()
> 1
> 2
> 5
> 3
>
> interesting.
Why? It just proves that "finally" works, and
executes when the return statement is encountered.
(The point of my examples was to show that finally can
actually override the value that would otherwise have been
returned. I thought that was interesting, but unfortunately
I'm not sure what your example adds to the previous two posts.
Maybe I'm just missing the point...)
-Peter
More information about the Python-list
mailing list