6.5.1 multi-Inheritance
Python also supports multiple inheritance forms. A class that can inherit multiple base classes is defined as follows:
Class DerivedClassName (Base1, Base2, Base3 ):
.
.
.
In most cases, you can consider the property query inherited from the parent class as follows: depth first, from left to right.
Instead of executing it twice in the same class with the same level of repetition. Therefore, if an attribute is not found in the derived class, it is first found in base1 and then in base1's base class. If it is not found there, it will be searched in base2 and so on.
In fact, it is a little more complicated than just mentioned. The execution sequence of the Methods dynamically changes in order to call super () collaboratively. This method is well known for calling the next method in some languages that support multi-inheritance. It is more powerful than the super call in the single inheritance language.
Dynamic sorting is required because at least one diamond relationship is displayed in all cases of multi-inheritance. (Starting from the underlying class, at least one parent class can be accessed through multiple paths ). For example, all classes inherit objects. Therefore, in each case of multiple inheritance, at least one path is provided to reach the object. to ensure that at least one method is used to access the base class, dynamic algorithms use a special method to normalize the search order. This method ensures that each class is in the order from left to right, and each parent class is only once, and that is unchanged. (That is, inheriting a class does not have the priority of its parent class). In short, these attributes make it possible to design a reliable and extensible class using multiple inheritance. For more information, see:
6.6 private variables
Other "private" variables that cannot be accessed except the object do not exist in python. However, most python code follows a rule: the name prefixed with the following line is considered as a non-public part of the API. It can be considered as a detailed implementation and requires no notification when it is changed.
Because there are legal use cases for private members of the class (that is, to avoid conflicting names defined in the subclass), all restrictions on this mechanism are supported. This mechanism is called name conversion. Any identifier in the form of _ spam (at least two starting underlines and at most one ending underline) can be replaced by _ classname_spam in writing. Here classname is the current class name. As long as this transformation occurs in the class definition, the syntax location that does not involve the identifier can be processed.
Name transformation is of great significance for the subclass to overload the method without affecting the parent method. For example:
This conversion rule was originally designed to avoid conflicts. If you want to access or modify a private variable, it is still possible. In some special cases, this method is more useful. For example, the debugger.
Note that the Code passed to exec () or eval () does not use the call class as the current class. This global variable has similar effects. Its function is limited to the Code for bytecode compilation. The same restrictions apply to getattr (), settattr (), delattr () functions, and when _ dict _ is directly referenced.