Skip to content

Instantly share code, notes, and snippets.

@f3rdy
Created March 21, 2016 16:13
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 f3rdy/4f210c400990bda2d548 to your computer and use it in GitHub Desktop.
Save f3rdy/4f210c400990bda2d548 to your computer and use it in GitHub Desktop.
Decorators
from functools import wraps
def hello(func):
@wraps(func) # fetch attributes from the original function
def proxy(*args, **kwargs):
print("Decorator Action")
return func(*args, **kwargs)
return proxy
@hello
def add(a, b):
return a + b
def say(text):
def _say(func):
def __say(*args, **kwargs):
print(text)
return func(*args, **kwargs)
return __say
return _say
@say('hello')
def sub(a,b):
return a-b
class C():
@staticmethod # This is a decorator necessary that func() can be called
def func():
print('Hallo')
c = C()
c.func()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment