0

How to manage the fonc arguments through a decorator?

Instead of a long awkward description, I have built an example of decorator I try to handle : check out "decor & arg _ test" on my profile, in case you would try yourself. I let some ~~ where I guess something related to arguments (and the wrap effect) should take place... https://code.sololearn.com/cQwvk2NKC8pW/?ref=app

29th May 2019, 10:56 PM
Baudhuin
Baudhuin - avatar
2 ответов
+ 1
Hello. You can pass parameters through the wrapper function and use them to call the actual function, like this. def dodg_divider(fonc) : def wrap(x,y) : r = fonc(x,y) w = float(x) % float(y) div_inaccuracy = (r-w, r+w) return r, div_inaccuracy return wrap I think you should call the fonc(x, y) only once inside the wrapper. This solution is not perfect yet.. You should pay attention to type conversions and type checks. I would put the try block outside, where you get the input() and make sure you only pass integers to the function. You can also avoid ValueError that way (if a float lile 5.2 is given). And design the return value so that it makes sense... Now it is a tuple that contains the function return value, and another tuple having the calculations inside the wrapper. https://code.sololearn.com/c3PX8u16c0bh/?ref=app
19th Jun 2019, 5:11 AM
Tibor Santa
Tibor Santa - avatar
+ 1
Thank you Tibor Santa! It looks good. I'll follow your advices and play with them.
23rd Jun 2019, 11:02 AM
Baudhuin
Baudhuin - avatar