Try-except-finally paradox
Jessica Ross
deathweasel at gmail.com
Thu Jan 30 00:56:16 EST 2014
I found something like this in a StackOverflow discussion.
>>> def paradox():
... try:
... raise Exception("Exception raised during try")
... except:
... print "Except after try"
... return True
... finally:
... print "Finally"
... return False
... return None
...
>>> return_val = paradox()
Except after try
Finally
>>> return_val
False
I understand most of this.
What I don't understand is why this returns False rather than True. Does the finally short-circuit the return in the except block?
More information about the Python-list
mailing list