Created
November 26, 2011 12:32
-
-
Save lvidarte/1395582 to your computer and use it in GitHub Desktop.
Context Manager API
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
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" |
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
__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