Reputation: 127
I am getting following error while performing a simple decorator code
"decorator_func() missing 1 required positional argument: 'original_func'"
Appreciate if someone points at the issue, thanks.
Here is the code:
def decorator_func(original_func):
def wrapper_func(*args, **kwargs):
return original_func(*args, **kwargs)
return wrapper_func()
@decorator_func() #also tried without calling i.e. @decorater_func
def displayInfo_func(name, age):
print('Display Info func ran with arguments ({}, {})'.format(name))
displayInfo_func
Thanks in advance.
Upvotes: 1
Views: 32
Reputation: 1633
The problem is while returning wrapper function you are calling it and that too without any arguments.
def decorator_func(original_func):
def wrapper_func(*args, **kwargs):
return original_func(*args, **kwargs)
return wrapper_func #instead of wrapper_func()
@decorator_func() #also tried without calling i.e. @decorater_func
def displayInfo_func(name, age):
print('Display Info func ran with arguments ({}, {})'.format(name))
Upvotes: 1