Created
May 2, 2017 06:11
-
-
Save gchiam/0094354b3155a636174822b45a208f27 to your computer and use it in GitHub Desktop.
context manager
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
import contextlib | |
@contextlib.contextmanager | |
def cm(): | |
info = {} | |
print 'start' | |
yield info | |
print 'end', info | |
if __name__ == '__main__': | |
with cm() as info: | |
print 'hello' | |
info['foo'] = 'bar' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment