0
Collecting reports exercice Python
Hi guys, here's my code: def decor(func): def wrap(): print('***') func() print('***') print('END OF PAGE') return wrap @decor def invoice(num): print("INVOICE #" +num) invoice(input()); I'm supposed to have the following: *** INVOICE #num *** END OF PAGE Could you help me understand what are the arguments I should implement in order for this code to work? I have some difficulties with decorators. Thanks for your help.
6 Respostas
+ 5
def decor(func):
def wrap(arg):
print('***')
func(arg)
print('***')
print('END OF PAGE')
return wrap
@decor
def invoice(num):
print("INVOICE #" +num)
invoice(input())
+ 2
your 'wrap' function returned by decorator should take an argument, wich you pass to the original 'func' function call ^^
+ 2
# for working with any signature:
def decor(func):
def wrap(*args,**kvargs):
print('***')
func(*args,**kvargs)
print('***')
print('END OF PAGE')
return wrap
@decor
def invoice(num):
print("INVOICE #" +num)
invoice(input())
+ 2
no, semi colon not needed in python, unless you want to have many statements at same line ;)
I will remove it (bad other languages reflex ;P)
+ 1
Thank you guys... Wasn't that hard.
+ 1
all the more that's just I didn't notice it while copying pasting OP code ^^