First page Back Continue Last page Overview Graphics

Better Way to Do it

Fortunately, we don't have to add all this code to our decorators to have these results. We can import the decorator "wraps" from functools instead and decorate our function in the decorator with it:

from functools import wraps

def greeting(func):

@wraps(func)

def function_wrapper(x):

""" function_wrapper of greeting """

print("Hi, " + func.__name__ + " returns:")

return func(x)

return function_wrapper