Python/Decorator

From Fundamental Ramen
< Python
Revision as of 04:00, 13 June 2019 by Tacoball (talk | contribs) (Created page with "<source lang="python"> def pre_hook(func): def wrapper(*args): a = args[0] + 1 b = args[1] + 1 return func(a, b) return wrapper </source> <sou...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
def pre_hook(func):
    def wrapper(*args):
        a = args[0] + 1
        b = args[1] + 1
        return func(a, b)
    return wrapper
def post_hook(func):
    def wrapper(*args):
        print(func(*args))
    return wrapper
def duo_hook(func):
    def wrapper(*args):
        a = args[0] + 1
        b = args[1] + 1
        sum = func(a, b)
        print(sum)
        return sum
    return wrapper