Answers for "python function decorators"

19

decorator python

def our_decorator(func):
    def function_wrapper(x):
        print("Before calling " + func.__name__)
        func(x)
        print("After calling " + func.__name__)
    return function_wrapper

@our_decorator
def foo(x):
    print("Hi, foo has been called with " + str(x))

foo("Hi")
Posted by: Guest on September-30-2020

Python Answers by Framework

Browse Popular Code Answers by Language