Created
September 4, 2014 07:33
-
-
Save mscook/af090514de45d05b5a44 to your computer and use it in GitHub Desktop.
counter decorator
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
print 80*"="+"\nThe 'counter' decorator\n"+80*"=" | |
def scount(wrapped): | |
def inner(*args, **kwargs): | |
inner.counter +=1 | |
return wrapped(*args, **kwargs) | |
inner.counter = 0 | |
return inner | |
@scount | |
def scount_me(): | |
pass | |
for i in range(4): | |
scount_me() | |
print "SCount called %i times" % (scount_me.counter) |
GrahamDumpleton
commented
Sep 4, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment