Friday, December 10, 2010

finally block can override enclosed return statement

>>> def print_then_return():
...    try:
...       return "returns"
...    finally:
...       print "finally"
...
>>> print_then_return()
finally
'returns'
>>> def override_return():
...    try:
...       return "returns"
...    finally:
...       return "finally"
...
>>> override_return()
'finally'

No comments:

Post a Comment