Skip to content

Instantly share code, notes, and snippets.

@sidchilling
Created April 29, 2013 06:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sidchilling/5480047 to your computer and use it in GitHub Desktop.
Save sidchilling/5480047 to your computer and use it in GitHub Desktop.
Script to show how to decorate a method in Python
# Decorated methods is same as decorating functions. Just take 'self' into consideration
def method_friendly_decorator(method_to_decorate):
def wrapper(self, lie):
lie = lie + 3
return method_to_decorate(self, lie)
return wrapper
class Hermione(object):
def __init__(self):
self.age = 19
@method_friendly_decorator
def say_your_age(self, lie):
return 'I am %s years old' %(self.age - lie)
h = Hermione()
print h.say_your_age(lie = 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment