示例如下

class A():
     def __init__(self):pass

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

当调用B创建对象时,会出现错误

TypeError: super() argument 1 must be type, not classobj

python中的super只能应用于新类,而不能应用于经典类。
新类的意思大概就是要有父类。
例如

class B(A):

经典类就是没有父类的类
例如

class A():

产生上面问题的原因就是对A类这个经典类调用了

super(A, self).__init__()

相关文章:

  • 2022-12-23
  • 2021-11-17
  • 2022-12-23
  • 2021-12-14
  • 2022-12-23
  • 2021-10-20
  • 2022-12-23
  • 2021-11-16
猜你喜欢
  • 2022-12-23
  • 2021-05-17
  • 2022-03-03
  • 2022-12-23
  • 2022-02-13
  • 2021-09-02
  • 2022-02-05
相关资源
相似解决方案