Документация гласит:
Python supports a form of multiple inheritance as well. A class
definition with multiple base classes looks like this:
class DerivedClassName(Base1, Base2, Base3):
<statement-1>
.
.
.
<statement-N>
For most purposes, in the simplest cases, you can think of the search
for attributes inherited from a parent class as depth-first, left-to-
right, not searching twice in the same class where there is an overlap
in the hierarchy. Thus, if an attribute is not found in
DerivedClassName, it is searched for in Base1, then (recursively) in
the base classes of Base1, and if it was not found there, it was
searched for in Base2, and so on.
Итак, у меня есть этот код для проверки:
class Class1:
c1_1 = 1.1
class Class2:
c2_1 = 2.1
class Blob(Class1, Class2):
def dump():
print('c1_1 = ' + str(c1_1))
Blob.dump()
Но я получаю это:
Traceback (most recent call last):
File "classinherit.py", line 13, in <module>
Blob.dump()
File "classinherit.py", line 11, in dump
print('c_1.1 = ' + str(c1_1))
NameError: name 'c1_1' is not defined
Документация, кажется, говорит, что Python сначала будет искать (в данном случае общеклассовую) переменную в области видимости класса Blob, и, не найдя ее, будет искать классы Class1 и Class2 ... но этого явно не происходит.
Что дает?