Created
May 31, 2014 06:40
-
-
Save kristianperkins/b96f908adf5d7d2b044a to your computer and use it in GitHub Desktop.
Obscure counting with the contextlib.contextmanager decorator
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
from contextlib import contextmanager | |
@contextmanager | |
def start_and_end(): | |
print 1 | |
yield | |
print 3 | |
# prints 1, 2 and 3 in order | |
with start_and_end(): | |
print 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment