Super function in Python multiple inheritance?
怪我咯
怪我咯 2017-05-18 10:50:04
0
2
516
class A:
    def __init__(self):
        print('A')
        
class B():
    def __init__(self):
        print('B')

class C(A, B):
    def __init__(self):
        super(C, self).__init__()
        print('C')
              

obj = C()

You can use the super method to call the method of the parent class, but how to use it in multiple inheritance?
The above code class C will call the __init__ method of class A, but if I want to call class A and class B# at the same time ##How to write the '__init__' method? Or just call the __init__ method of class B?

Of course, this can be achieved using the unbound method.

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(2)
phpcn_u1582

Just call it explicitly, you can choose freely.
A.__init__(self)A.__init__(self)
B.__init__(self)B.__init__(self)

迷茫

python-super

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!