+ 5
I need help with decorators in Python.
https://code.sololearn.com/cK7xx5ydzKf7/?ref=app In this code I can't understand these 2 things: 1. The job of the last line of this code; 2. And the last line of the decor funtion, I mean why that wrap doesn't have a pair of braces just after it like this wrap()?
3 ответов
+ 6
Last line is calling the decorated function
decorated()
Last line of decorated function
return wrap
You are returning the function, not calling it.
The decorated function is kept in variable called "decorated" and it could be called later with decorated()
+ 2
1 - decorated is another name for the function decor(print_text), and it is also a decoration due to the wrap(), so to actually use this function you must call it through decorated or use the decorator @decor above a function. Thus decorated(). (Because it returns a function)
2 - it is because you want it to return a function, not run it. If you would return wrap(), it wouldn't run firstly because func is not defined in that scope.
0
I think that this code could help
https://code.sololearn.com/cXiJWAB6AhS9/?ref=app