Python: new class and legacy class

The new class early in the 2.2 appeared, so the old class is fully compatible with the problem, Python3 in the class are all new style classes. There may be a problem MRO (new class inheritance is to understand the next algorithm based on C3, the old class is the depth priority), there are many <Python core programming> I talked about.

一个旧式类的深度优先的例子

class A():
def foo1(self):
print “A”
class B(A):
def foo2(self):
pass
class C(A):
def foo1(self):
print “C”
class D(B, C):
pass

d = D()
d.foo1()

A

According to look like the classic rules of priority order from left to right depth when accessing d.foo1 () is, D class is not ... then look up, first find B, there is no depth-first, access to A, found foo1 (), so this time the call is foo1 a (), resulting in a C rewrite of foo1 () is bypassed

Guess you like

Origin blog.csdn.net/weixin_44523387/article/details/91609977