The main contents of this section :
1. review of the pass decorator
2. information about the function
3. decorative Adorner with parameters
4. a plurality of adorners are decorated at the same time. Functions
? . review of the pass-through decorator
Opening and closing principle : open to increase function . enclosing the modified code
Decorator's work? : adds functionality to functions without changing the original code
The way the decorator is written :
Execution process:
In fact, executing target_func () is the execution of the inner function. The inner function executes the code before the target function, executes the target function, and then executes the code after the target function.
How to get useful information about a function:
Function name. __name__ can see the name of the functions
Function name. __doc__ can view functions document comments
Although the call is the Target_func function, but printed out is the inner function, this will inevitably give me misunderstanding, so we have to change back
PS: When *args and **kwargs break up, when to converge
1. when the parameter is received, it is aggregated , parameter declaration
2. passing parameters is scattered , passing arguments to the function
Three--Decorator
Execution order: executes Wrapper_out first (False), the return value is wrapper, and then @wrapper or the same as the previous adorner, one execution at a time.
four . multiple adorners decorated with a function
Read first, then the code .
This order can be smoothed by itself. Perform adorner 1 and then perform adorner 2
Python Basics 12 Adorner advanced