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
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
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)
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us