Reputation: 3937
I am unsure why the code below results in an error. I am just creating a Sub-Class Option
to the base class Security
and try to use super.get_description()
in the get_description()
function which results in an Error.
class Security(object):
def __init__(self, name, BriefDesc):
self.name = name
self.BriefDesc = BriefDesc
def __str__(self):
return self.name + ' ' + self.BriefDesc + ': ' + self.get_description()
def get_description(self):
return 'no detailed description.'
class Option(Security):
def __init__(self):
Security.__init__(self, 'Option', '(Derivative Security)')
def get_description(self):
return super.get_description() # Error here when print is executed. I am unsure why
def study_security(security):
print security
print study_security(Option()) # Results in an error
Upvotes: 0
Views: 39
Reputation:
You need to call super
and pass in the correct arguments1:
return super(Option, self).get_description()
Here is a link to the documentation for super
.
1This last part is only necessary in Python 2.x though. In Python 3.x, you can just do:
return super().get_description()
Upvotes: 1