Skip to content

Instantly share code, notes, and snippets.

@lvidarte
Created November 26, 2011 12:32
Show Gist options
  • Save lvidarte/1395582 to your computer and use it in GitHub Desktop.
Save lvidarte/1395582 to your computer and use it in GitHub Desktop.
Context Manager API
class Context(object):
def __init__(self):
print '__init__()'
def __enter__(self):
print '__enter__()'
return self
def __exit__(self, exc_type, exc_val, exc_tb):
print '__exit__()'
with Context():
print "Doing work in the context"
__init__()
__enter__()
Doing work in the context
__exit__()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment