Skip to content

Instantly share code, notes, and snippets.

@varhub
Last active September 10, 2015 12:35
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 varhub/dc1a5dec0a263e0a809e to your computer and use it in GitHub Desktop.
Save varhub/dc1a5dec0a263e0a809e to your computer and use it in GitHub Desktop.
Example of how to use decorators
## Public Domain
# Victor Arribas <v.arribas.urjc@gmail.com>
def deco(fn):
def wrapper(*args, **kwargs):
print 'wrapped'
fn(*args, **kwargs)
return wrapper
@deco
def test():
print 'test'
if __name__ == '__main__':
test()
class MyClass:
def deco(fn):
def wrapper(self, *args, **kwargs):
print 'wrapped(self)'
fn(self, *args, **kwargs)
return wrapper
@deco
def test(self, i):
print "test",i
if __name__ == '__main__':
c = MyClass()
c.test(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment