prof-rossetti / intro-to-python

An Introduction to Programming in Python
Other
97 stars 245 forks source link

Decorators / Functools Wraps #86

Open s2t2 opened 3 years ago

s2t2 commented 3 years ago

References:


from functools import wraps

def my_decorator(f):
    @wraps(f)
    def wrapper(*args, **kwds):
        print('Calling decorated function')
        return f(*args, **kwds)
    return wrapper

@my_decorator
def example():
    """Docstring"""
    print('Called example function')

example()