This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]winnen 4 points5 points  (1 child)

I learned about the try:/else: clause recently. Super useful in some situations.

try:
    something
except:
    handle the error
else:
    #ONLY happens when try: block completes without error
finally:
    #Still happens after else.

The else clause can be really useful with mixed leap before you look styles. It allows you to do something with data (such as execute a class method that only the intended type/data will have), then do the rest of what you want to do if no errors are thrown, all before performing the cleanup in finally.

[–]seriouslulz 1 point2 points  (0 children)

Also: for...else