Python 2.7 __init__() takes exactly 2 arguments (3 given)

前端 未结 2 1186
长情又很酷
长情又很酷 2021-01-25 07:31

I\'ve got these classes. Person is the parent class and Student is the child class:

class Person(object):
    def __init__(self, name):         


        
2条回答
  •  野性不改
    2021-01-25 08:19

    You can use

    super(Student, self).__init__(name)
    

    in which self has been passed to init method,so you don't need to write it out again in __init__ method. But if you use

    super(Student, Student).__init__(self, name)
    

    or

    super(Student, self.__class__).__init__(self, name)
    

    you have to write down self in __init__ method.

提交回复
热议问题