So what is a 'wrapper' or 'decorator' function in python. This is actually
considered a pretty advanced topic; I would guess, because only someone
with an advanced problem would think of using this. In point of fact,
it is not all that difficult to understand.
The core concept is one function calling another as its functionality. Below,
all that function2 does is call another; in this case, function1.
Here, function1 defines another 'wrapper' function, added onto whatever
it is the invoqued function - function2 - does. Function2 is said to be 'decorated' with
function1 ie cannot run without it.
Below, a use case, where the developer might wnat to know how long it takes
for function 2 to run...
No comments:
Post a Comment