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)

8th Dec 2021, 11:13 PM
Kovalov Evgen
Kovalov Evgen - avatar
3 Réponses
+ 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)
8th Dec 2021, 11:26 PM
ChaoticDawg
ChaoticDawg - avatar
+ 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).
8th Dec 2021, 11:39 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
ChaoticDawg Thanks. But where do we get "arg"?
8th Dec 2021, 11:34 PM
Kovalov Evgen
Kovalov Evgen - avatar