def lowercasewrapper(func):
def wrapper(*args, **kwargs):
return [item.lower() for item in func(*args, **kwargs)]
return wrapper
I understand what decorators do, I have implemented the decorator above into my code and it works, but I'm little unsure about a few things.
Why can't (func) be replaced by (*args, **kwargs) and in the process remove the def wrapper line? I'm guessing the first 2 lines don't do the same thing, but to me that's what it seems like. It seems like:
def lowercasewrapper(accept function) def wrapper(accept function)
What is the significance of the word 'func' here? I noticed I can replace that word with anything and my code still works. Does the function I put below @lowercasewrapper just feed into the decorator regardless of whats in the '( )'?
Also, a little off topic but the word item also has no significance right? I can replace that with any word as well and it still works.
I would appreciate if anyone would try to help and explain and answer in detail instead of redirecting me to a "what's a decorator" thread.