Created
May 11, 2018 20:59
-
-
Save Psycojoker/d67c639e5a32b5d019e9b93a045019f4 to your computer and use it in GitHub Desktop.
finally magic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def brol(fail=False): | |
try: | |
print "in try" | |
if fail: | |
raise Exception() | |
return "try" | |
except: | |
print "in exception" | |
return "exception" | |
finally: | |
print "in finally" | |
return "ok" | |
print brol() | |
print "=====" | |
print brol(True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ python finally.py | |
in try | |
in finally | |
try | |
===== | |
in try | |
in exception | |
in finally | |
exception | |
Press ENTER or type command to continue | |
in try | |
in finally | |
try | |
===== | |
in try | |
in exception | |
in finally | |
exception |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment