-
Decorative Device
An adorner is essentially a Python function that allows other functions to add extra functionality without any code changes, and the return value of the adorner is also a function object.
-
Descriptor
A descriptor is a class that implements a specific protocol, including, for this protocol, a __get__ __set__ __delete__ method.
-
Closed Package
-
- Closures refer to functions that extend the scope. It contains non-global variables that are referenced in the body of the function definition, but are not defined in the definition body.
- An intrinsic function can use the behavior of an external function variable, which is called a closure.
- When a function is nested, and a child function references a variable in the parent function, the scope of the variable can be accessed to form a closure.
- If a child function does not have access to a variable in the parent function, there is no closure.
-
Meta-Class (metaclass)
The instance is the class class, by default, the class in Python is an instance of the type class, for example, the type (int) results in the type class. Therefore, the type is a meta-class. The user can define the meta class by extending the type class.
-
Meta programming (metaprogramming)
The program is written using the program runtime information to change the behavior of the program. For example, ORM might introspect the declaration of a model class, determine how to validate the fields in a database record, and convert the database type to a Python type.
-
Callback Functions (callbackfunction)
A function that is first passed to the middle function is called a callback function.
Cases.
You go to a shop to buy things, just what you want to have no goods, so you left your phone in the shop clerk, after a few days the store has goods, the clerk called you, and then you received a call to the store to pick up the goods. In this example, your phone number is called a callback function, you leave the phone to the clerk called the registration callback function, the store later in the goods called triggered the callback associated event, the clerk called you called Call callback function, you go to the store to fetch goods called response callback event.
-
Start function
The starting function refers to the caller of the intermediate function.
-
Blocking callbacks
In a blocking callback, the call to the callback function must occur before the start function returns.
-
Deferred callback
In a deferred callback, the call to the callback function may be after the start function returns.
-
Weak references
A weak reference is a reference that cannot ensure that the object it references is not reclaimed by the garbage collector.
An object may be reclaimed at any time if it is referenced only by a weak reference.
The primary function of a weak reference is to reduce the number of unnecessary objects in memory by reducing circular references.
Python reclaims this object when the object's reference count is 0 or if only the weak reference to the object exists
-
Monkey Patch (monkey patching)
Used to dynamically modify existing code at run time without the need to modify the original code.
Typically, you add features or fix bugs.
The main uses are:
-
Dynamically replace methods, properties, and so on at run time
import json import ujson def monkey_patch_json(): json.__name__ = ‘ujson‘ json.dumps = ujson.dumps json.loads = ujson.loads
-
Add features that were not supported without modifying third-party code
-
Add patches to in-memory objects at run time instead of adding them to the disk's source code
Monkey patches in memory play a role, will not modify the source code. Therefore, it is valid only for the currently running program instance. This is considered a temporary workaround because the monkey patch destroys the encapsulation and easily causes the program to be tightly coupled to the implementation details of the patch code.
-
Duck type
A form of polymorphism.
An object's valid semantics are determined not by inheriting from a particular class or implementing a particular interface, but by the collection of current methods and properties .
-
Context Manager
An __enter__ __exit__ object that implements a special method and is used in a with block.
-
Abstract base class, (abstractbaseclass, ABC)
You cannot instantiate a class that can only be extended. Python implements the interface via ABC. In addition to inheriting ABC, a class can also register as a virtual subclass of ABC. Declares itself to implement the interface.
- Sub-Program
-
Co-process
Generators for concurrent programming
Functions that can pause execution
-
Grammatical sugars (syntactical sugar)
Also known as icing syntax, is a convenient syntax that does not affect program functionality, but can improve code readability.
-
__dict__
__dict__is a dictionary used to store object properties whose key is the property name and the value of the property.
-
LEGB Principles
Local (function), native
Enclosing function local, closure
Global (module), globally
Builtion (Python), module
- Delay binding
- The difference between GET, POST, put
- Cookie (client hold state)
-
Session (server-side hold state)
The session mechanism may need to use a cookie mechanism to achieve the purpose of preserving the identity