调用多重继承函数在 python 中失败

calling multiple inheritance function is failing in python

我正在尝试调用 python 中的多重继承函数,但出现了一些错误

class A:
    def __init__(self):
        self.name = "kiran"
class B:
    def __init__(self):
        self.num = 10
class Merge(A,B):
    def disp(self):
        print self.num

obj_var = Merge()
print obj_var.disp()

错误:

Traceback (most recent call last):
  File "test_calss_obj.py", line 12, in <module>
    print obj_var.disp()
  File "test_calss_obj.py", line 9, in disp
    print self.num
AttributeError: Merge instance has no attribute 'num'

为什么会出现这个错误,我需要一个打印为 10 的输出

您缺少 Merge 的构造函数:

class Merge(A, B):
    def __init__(self):
       A.__init__(self)
       B.__init__(self)
    def disp(self):
        print self.num