Created
June 18, 2010 21:02
-
-
Save paulosuzart/444229 to your computer and use it in GitHub Desktop.
This file contains 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 functools | |
def printAround(key): | |
""" | |
snipet to remember prepare cached invocations in memcached. | |
""" | |
def decorator(f): | |
@functools.wraps(f) | |
def new_f(*args): | |
print 'entering', f.__name__ | |
print 'key ', key | |
f(*args) | |
print 'done' | |
return new_f | |
return decorator | |
@printAround('ops') | |
def hi(name): | |
print ('hi %s' % name) | |
hi('paul') | |
""" | |
prints: | |
entering hi | |
key ops | |
hi paul | |
done | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment