Re: INHERITANCE in python3
On 12/19/2019 06:22 AM, Pieter van Oostrum wrote: Random832 writes: On Wed, Dec 18, 2019, at 23:10, wrote: [vahid asadi] my problem here is why this attribute is not recognize by python and it raise an traceback error that said 'there is no such p.family attribute'. although i use multiple inheritance with 'super ' it not works. thanks for your help. class Username: def __init__(self, name, *args): self.name= name class Userfamily: def __init__(self, family, *args): self.family = family class Person(Username, Userfamily): def __init__(self, *args): super().__init__(*args) p = Person("v", "aaa") print(p.name) print(p.family) [Random32] The Username class also needs to call super(). In general, super() is intended to be used with all classes that might be part of a multiple inheritance hierarchy, not just the derived one. [Pieter van Oostrum] Just for safety, also add it* to the Userfamily class. * a call to super() (in case anybody else misreads that like I did) -- ~Ethan~ -- https://mail.python.org/mailman/listinfo/python-list
Re: INHERITANCE in python3
Random832 writes: > On Wed, Dec 18, 2019, at 23:10, vahid asadi via Python-list wrote: >> HI guys this is my first post on python mailing lists ever and i glad >> to do this. >> my problem here is why this attribute is not recognize by python and it >> raise an traceback error that said 'there is no such p.family >> attribute'. although i use multiple inheritance with 'super ' it not >> works. thanks for your help. >> >> ``` class Username: def __init__(self,name,*args): self.name >> = name >> class Userfamily: def __init__(self,family,*args): >> self.family = family >> class Person(Username,Userfamily): def __init__(self,*args): >> super().__init__(*args) >> >> >> p = Person("v","aaa")print(p.name)print(p.family)``` Please next time, supply a properly indented Python source, with only normal ASCII spaces, not no-break spaces, i.e. exactly like in your Python source code. > > The Username class also needs to call super(). In general, super() is > intended to be used with all classes that might be part of a multiple > inheritance hierarchy, not just the derived one. Just for safety, also add it to the Userfamily class. -- Pieter van Oostrum www: http://pieter.vanoostrum.org/ PGP key: [8DAE142BE17999C4] -- https://mail.python.org/mailman/listinfo/python-list
Re: INHERITANCE in python3
On Wed, Dec 18, 2019, at 23:10, vahid asadi via Python-list wrote: > HI guys this is my first post on python mailing lists ever and i glad > to do this. > my problem here is why this attribute is not recognize by python and it > raise an traceback error that said 'there is no such p.family > attribute'. although i use multiple inheritance with 'super ' it not > works. thanks for your help. > > ``` class Username: def __init__(self,name,*args): self.name > = name > class Userfamily: def __init__(self,family,*args): > self.family = family > class Person(Username,Userfamily): def __init__(self,*args): > super().__init__(*args) > > > p = Person("v","aaa")print(p.name)print(p.family)``` The Username class also needs to call super(). In general, super() is intended to be used with all classes that might be part of a multiple inheritance hierarchy, not just the derived one. -- https://mail.python.org/mailman/listinfo/python-list
INHERITANCE in python3
HI guys this is my first post on python mailing lists ever and i glad to do this. my problem here is why this attribute is not recognize by python and it raise an traceback error that said 'there is no such p.family attribute'. although i use multiple inheritance with 'super ' it not works. thanks for your help. ``` class Username: def __init__(self,name,*args): self.name = name class Userfamily: def __init__(self,family,*args): self.family = family class Person(Username,Userfamily): def __init__(self,*args): super().__init__(*args) p = Person("v","aaa")print(p.name)print(p.family)``` -- https://mail.python.org/mailman/listinfo/python-list