Skip to content

Instantly share code, notes, and snippets.

@tomncooper
Created October 2, 2017 15:33
Show Gist options
  • Save tomncooper/68f3ec51e513c4270084bdc12bc38de3 to your computer and use it in GitHub Desktop.
Save tomncooper/68f3ec51e513c4270084bdc12bc38de3 to your computer and use it in GitHub Desktop.
Decorator examples
class after5(object):
def __init__(self, func):
self.func = func
self.counter = 0
def __call__(self):
if self.counter > 4:
self.func()
self.counter += 1
if __name__ == "__main__":
@after5
def doit():
print("Yo!")
# Theses should print nothing
doit()
doit()
doit()
doit()
doit()
# This should print something
doit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment