0
Decorate in Py. Have errors
def decor(func): def wrap(): print("***") func() print("***", "\nEND OF PAGE") return wrap @decor def invoice(num): print("INVOICE #" +num) num = input() invoice(num)
3 Antworten
+ 3
The wrap function needs to have a parameter to pass to func, since the invoice function accepts a parameter.
def decor(func):
def wrap(arg):
print("***")
func(arg)
print("***", "\nEND OF PAGE")
return wrap
@decor
def invoice(num):
print("INVOICE #" +num)
num = input()
invoice(num)
+ 2
It can be any name, could have just as easily been x. It's a function parameter the same as num. I just called it arg short for argument as an example. So, num once passed to the wrap function via the decor function will be called arg in that scope and is passed as such to the func call (which is what the invoice function is referred to in the same scope).
+ 1
ChaoticDawg Thanks. But where do we get "arg"?