I. Adorner pre-placement knowledge essentials
1. Namespaces
places where names and variables are bound
Classification of namespaces:
Built-in namespaces: where the Python interpreter starts, storing its own name. (such as built-in functions)
Global namespaces: Where file-level names are stored when the file is executed
Local namespaces: During the execution of a file, if the function is called, where the function is used to hold the default name, the call takes effect, and the call ends after it expires.
Load order: Built-in--------"Global----------" local
Lookup Order: Local--------"Global----------" built-in
2. Scope
Scope: Range of effects
(1). Global scope (Globals ())
Global survival, globally valid
(2). Local scope (locals ())
Temporary survival, partially effective
Note: 1. Scope relationship, function definition has been determined, and function call location independent, in the call function is back to the original definition function
Position to find the scope relationship.
3. Closure function
Definition: A function defined inside that contains a reference to an outer scope, not a reference to a global scope, which is a closure function
Two. Decorative Device
Adorner Purpose: to follow the principle of the premise of adding new functions for other functions
the adorner follows the principle: 1. Do not modify the source code of the adorned object 2. Do not modify the calling method of the called Object
Examples of non-parametric adorners:
Example of a parameter function:
Python Road-Decorators