Here is the code:
# Decorators
def on_or_off(func):
def wrapper(*args, on_switch, **kwargs):
if on_switch:
func(*args, on_switch=on_switch, **kwargs)
return wrapper
@on_or_off
def print_101(on_switch=False):
print ('101')
print_101()
# TypeError: wrapper() missing 1 required keyword-only argument: 'on_switch'
I thought the default on_switch
value will pass to the wrapper function, but it doesn't. How can the line print_101()
remains the same and allows for passing the default on_switch
value to the wrapper decorator function?