Почему многоуровневое наследование не работает ?
class Grandfather: last = 'wilson' citizenship = 'american' residence = 'Detroit' def __init__(self,first,college,age,career,workplace): self.first = first self.college = college self.age = age self.career = career self.workplace = workplace self.email = first + '-' + Grandfather.last + '@email.com' @property def fullname(self): return '{} {}'.format(self.first,Grandfather.last) def __str__(self): return '{} {}'.format(self.first,self.last) @property def history(self): return 'my name is : {}, i graduated from {} and work as {} in {}'.format\ (self.fullname,self.college,self.career,self.workplace) @classmethod def set_residence(cls,newR): cls.residence = newR @classmethod def set_cit(cls,new_cit): cls.citizenship = new_cit class Father(Grandfather): def __init__(self,first,college,age,career,workplace,sport,wife): super().__init__(first,college,age,career,workplace) self.sport = sport self.wife = wife class Son(Father): def __init__(self,first,college,age,career,workplace,sport,wife,Vedio_Game,Car): super().__init__(self,first,college,age,career,workplace,sport,wife) self.Vedio_Game = Vedio_Game self.Car = Car john = Grandfather('john','stanford',70,'engineer','Ford') mark = Father('mark','MIT',40,'CScientist','SONY','Tennis','Sara') Maik = Son('Maik','MIT',26,'SoftwareEngineer','Google','tennis','caro','MineCraft','Toyota') if __name__ == '__main__': print(john.fullname) print(john) print(john.history) Grandfather.set_residence('Frankfurt') print(Grandfather.residence) print('############') print(mark.fullname) print(mark) print(mark.history) print(mark.residence) print('###########') print(Maik.fullname) print(Maik) print(Maik.residence)
Что я уже пробовал:
добавив все существующие атрибуты отец и Дед классов для класса сына
после того как файл с Python выполняется, она бросает ошибку:
Traceback (most recent call last): File "my.py", line 57, in <module> Maik = Son('Maik','MIT',26,'SoftwareEngineer','Google','tennis','caro','MineCraft','Toyota') File "my.py", line 40, in __init__ super().__init__(self,first,college,age,career,workplace,sport,wife) TypeError: __init__() takes 8 positional arguments but 9 were given
Richard MacCutchan
В чем же вопрос?