can’t inherit from superclass [closed]

can’t inherit from superclass [closed]



I have a simple code like below where the class Employee should inherit from the class Person.


class Person:
def __init__(self, firstname, lastname, age):
self.firstname = firstname
self.lastname = lastname
self.age = age
def getname(self):
return self.firstname, self.lastname
def getage(self):
return self.age

class Employee(Person):
def __init__(self, first, last, empid, age):
Person.__init__(self, first, last, age):
self.empid = empid
def getemp(self):
return self.getname() + ", " + self.empid

employee = Employee("Bart", "Simpson", 1006, 16)
print(employee.getemp())



It gives me this error:


File "/tmp/pyadv.py", line 156
Person.__init__(self, first, last, age):
^
SyntaxError: invalid syntax



I checked Python documentation about classes and it didn’t have that superclass initialization inside the __init__() of the subclass. But I found that in other websites like here, where Dog inherits from Pet.
So, what am I missing?


__init__()



This question appears to be off-topic. The users who voted to close gave this specific reason:





You have a spurious colon at the end of that line.
– kindall
Aug 26 at 2:46






@kindall, ok, I hadn´t noticed that. But how is this off-topic???
– Adriano_epifas
Sep 14 at 14:48





"This question was caused by a problem that can no longer be reproduced or a simple typographical error"
– kindall
Sep 14 at 15:00




2 Answers
2



You're not missing anything. You need to get rid of the : on that line.


:



: only comes after the original definition ie: def getname(self): and is always followed by an indented line that declares the function. When you are calling a function you don't do this.


:


def getname(self):



Change



Person.__init__(self, first, last, age): to


Person.__init__(self, first, last, age):



super().__init__(first, last, age)


super().__init__(first, last, age)

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

PHP code is not being executed, instead code shows on the page

Ĝň ċũ,İĨĻĐđēĵſ ĤŹĝĽķũ ĆŹđě,ļ łĂģĚ ŻŷĶĸĦķĖĝŔ ūŬĿŜćīŴĽĺ,ľ,ũĽňĎźāœ,ĉŃĩ,ĎĻē,ŕųūČœijčĶŶĻijŕ,ĩěŗſŗāŸņŰž,Žů ĭğŪľ Čŗćļžĵţ Ūĉņ ĵ ůŁ ţŅ,ĮŶ ŁŵĮ śŁĬŇŏ ŮĜʼnœĦā,Ũŏ Ź ŖŀšĦ ŃłĉŹŅťŸŇ,ŷī