class Person:
    def __init__(self,name,age):
        self._name = name
        self._age = age


class Student(Person):
    def __init__(self,name,age,id):
        super(Student, self).__init__(name,age)
        self._id = id

原因:

super只能用于python的新类中,如果基类是经典类,则会报这个错

新类:所有类都必须要有继承的类,如果什么都不想继承,就继承object类。
经典类:什么都不继承的类,如上面的Person就是经典类。所以报错

解决方法:

让Person继承object

class Person(object):

 

相关文章:

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