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.

18th Feb 2021, 7:22 PM
Hugo Mouls
Hugo Mouls - avatar
6 Réponses
+ 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())
18th Feb 2021, 7:29 PM
visph
visph - avatar
+ 2
your 'wrap' function returned by decorator should take an argument, wich you pass to the original 'func' function call ^^
18th Feb 2021, 7:27 PM
visph
visph - avatar
+ 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())
18th Feb 2021, 7:32 PM
visph
visph - avatar
+ 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)
16th Mar 2021, 9:08 PM
visph
visph - avatar
+ 1
Thank you guys... Wasn't that hard.
18th Feb 2021, 8:38 PM
Hugo Mouls
Hugo Mouls - avatar
+ 1
all the more that's just I didn't notice it while copying pasting OP code ^^
16th Mar 2021, 9:35 PM
visph
visph - avatar