Skip to content

Instantly share code, notes, and snippets.

ofunc = orig_func
print(ofunc.__name__)
print(ofunc.__doc__)
def decor_factory(flag=True):
def decor_func(fn):
def wrapper_func(*args,**kwargs):
"""
This is the wrapper function
"""
if flag:
print('Flag is True')
else:
print('Flag is False')
def decor_factory(flag=True):
def decor_func(fn):
from functools import wraps
@wraps(fn)
def wrapper_func(*args,**kwargs):
"""
This is the wrapper function
"""
if flag:
print('Flag is True')
def decor_factory(flag=True):
def decor_func(fn):
from functools import wraps
@wraps(fn)
def wrapper_func(*args,**kwargs):
"""
This is the wrapper function
"""
if flag:
print('Flag is True')
ofunc = orig_func
print(ofunc.__name__)
print(ofunc.__doc__)
# This is the original function.
def orig_func(a,b,c):
"""
This is the original function
returns the product of a,b,c
"""
return (print('This is the product:',a*b*c))
def decor_func(fn):
def wrapper_func(*args,**kwargs):
"""
This is the wrapper function
"""
print('Execute this code before the main function is executed')
return fn(*args, **kwargs)
return wrapper_func
#Method:1
orig_func=decor_func(orig_func)
# or
#Method2
@decor_func
def orig_func(a,b,c):
"""
returns the product of a,b,c
help(orig_func)
def decor_func(fn):
def wrapper_func(*args,**kwargs):
"""
This is the wrapper function
"""
print('Execute this code before the main function is executed')
return fn(*args, **kwargs)
#Assign the original function name and the docstring to the wrapper name and doctstring.
wrapper_func.__name__ = fn.__name__