Skip to content

Instantly share code, notes, and snippets.

@kristianperkins
Created May 31, 2014 06:40
Show Gist options
  • Save kristianperkins/b96f908adf5d7d2b044a to your computer and use it in GitHub Desktop.
Save kristianperkins/b96f908adf5d7d2b044a to your computer and use it in GitHub Desktop.
Obscure counting with the contextlib.contextmanager decorator
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