Header Ads

Responsive Ads Here

Decorators in Python

Decorators in Python



# enhances the functionality of other functions --> Decorators
from functools import wraps

def deco(func):
    @wraps(func)
    def wrapper():
        '''wrapper is an awesome function'''
        print("This is my func...")
        func()
    return wrapper

# func = first_func

@deco
def first_func():
    '''First func is an awesome function'''
    print("This is first function...")

@deco
def second_func():
    '''Second func is an awesome function'''
    print("This is second function...")


first_func()
second_func()

print(first_func.__doc__)
print(second_func.__doc__)
print(first_func.__name__)
print(second_func.__name__)

Powered by Blogger.