56341 发表于 2016-9-12 09:13:41

python中super出现的TypeError: must be type, not classobj 原因及解决

执行一下代码,出现错误,TypeError: must be type, not classobj

class A():
    def __init__(self):
      print("Enter A")
      print("Leave A")

class B(A):
    def __init__(self):
      print("Enter B")
      super(B, self).__init__()
      print("Leave B")

class C(A):
    def __init__(self):
      print("Enter C")
      super(C, self).__init__()
      print("Leave C")

class D(A):
    def __init__(self):
      print("Enter D")
      super(D, self).__init__()
      print("Leave D")

class E(B, C, D):
    def __init__(self):
      print("Enter E")
      super(E, self).__init__()
      print("Leave E")

E()
输出错误:
Traceback (most recent call last):
File "F:/test5.py", line 35, in <module>
    E()
File "F:/test5.py", line 32, in __init__
    super(E, self).__init__()
TypeError: must be type, not classobj

百度之后发现,python中super只能应用于新类,而不能应用于经典类

页: [1]
查看完整版本: python中super出现的TypeError: must be type, not classobj 原因及解决