Python Decorators
class decoratorWithoutArgs(object):
def __init__(self, fn):
self.fn = fn
def __call__(self, *args):
self.fn(*args)
class decoratorWithArgs(object):
def __init__(self, arg):
self.arg = arg
def __call__(self, f):
def wrapped(*args):
f(*args)
return wrapped
@decoratorWithoutArgs
def foo():
pass
@decoratorWithArgs(10)
def bar():
pass
if __name__ == "__main__":
foo()
bar()