# This version only accepts one argument
# def shout(fn):
# def wrapper(name):
# return fn(name).upper()
# return wrapper
# This version works with any number of args
def shout(fn):
def wrapper(*args, **kwargs):
return fn(*args, **kwargs).upper()
return wrapper
@shout
def greet(name):
return f"Hi, I'm {name}."
@shout
def order(main, side):
return f"Hi, I'd like the {main}, with a side of {side}, please."
@shout
def lol():
return "lol"
print(greet("todd"))
print(order(side="burger", main="fries"))
print(lol())
In the above code,
def wrapper(*args, **kwargs):
print(f"abc is {fn.__name__}")
return fn(*args, **kwargs).upper()
return wrapper
When wrapper functions executed, how does it knows the value of arguments which are to be assigned to , * args and **kwargs. We have not defined the values of arguments here, but instead func is given the parameters.
side="burger", main="fries".
**kwargs open up the dictionary but when did we defined such dictionary?
How does side="burger", main="fries" are set as arguments of wrapper function and Why are they being assigned to args and kwargs ? Why are arguments given to fync being assigned to parameters of wrapper function?