Answers for "python call function that need args with decorator"

0

python decorator *args **kwargs

from functools import wraps

def my_decorator(f):
    @wraps(f)
    def wrapper(*args, **kwargs):
        print('Calling decorated function')
        return f(*args, **kwargs)
    return wrapper
Posted by: Guest on September-08-2020
0

python call function that need args with decorator

@decorator
def foo(*args, **kwargs):
    pass
# translates to

foo = decorator(foo)
# So if the decorator had arguments,

@decorator_with_args(arg)
def foo(*args, **kwargs):
    pass
# translates to

foo = decorator_with_args(arg, foo)
Posted by: Guest on January-27-2022

Code answers related to "python call function that need args with decorator"

Python Answers by Framework

Browse Popular Code Answers by Language