[Python-Dev] Fwd: try...else
M.-A. Lemburg
mal@lemburg.com
Thu, 28 Dec 2000 17:52:36 +0100
Moshe Zadka wrote:
>
> On Thu, 28 Dec 2000, "M.-A. Lemburg" <mal@lemburg.com> wrote:
>
> > He does have a point however that 'return' will bypass
> > try...else and try...finally clauses. I don't think we can change
> > that behaviour, though, as it would break code.
>
> It doesn't bypass try..finally:
>
> >>> def foo():
> ... try:
> ... print "hello"
> ... return
> ... finally:
> ... print "goodbye"
> ...
> >>> foo()
> hello
> goodbye
Hmm, that must have changed between Python 1.5 and more recent
versions:
Python 1.5:
>>> def f():
... try:
... return 1
... finally:
... print 'finally'
...
>>> f()
1
>>>
Python 2.0:
>>> def f():
... try:
... return 1
... finally:
... print 'finally'
...
>>> f()
finally
1
>>>
--
Marc-Andre Lemburg
______________________________________________________________________
Company: http://www.egenix.com/
Consulting: http://www.lemburg.com/
Python Pages: http://www.lemburg.com/python/