Skip to content

Instantly share code, notes, and snippets.

@satiani
Last active December 25, 2015 00:09
Show Gist options
  • Save satiani/6885361 to your computer and use it in GitHub Desktop.
Save satiani/6885361 to your computer and use it in GitHub Desktop.
class TestContext(object):
def __init__(self):
self.entered = False
self.exited = False
def __enter__(self):
self.entered = True
def __exit__(self):
self.exited = True
c = TestContext()
try:
with c:
raise Exception('dummy')
except:
pass
# prints True
print c.entered
# prints False
print c.exited
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment