423,818 Members | 2,266 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,818 IT Pros & Developers. It's quick & easy.

Python subclass function call

P: 7
My questions is regarding subclasses in Python.

For example, if I have the following code.

Expand|Select|Wrap|Line Numbers
  2. class Myclass:
  3.       def __init__(self, input)
  4.           self.input = input
  6.       def function(self, input)
  7.           return output
  9. class MySubclass(Myclass)
  10.       def function(self, input)
  11.           return output
The question is how would you access the function in the sub class as opposed to the one in the base class?
2 Weeks Ago #1
Share this Question
Share on Google+
2 Replies

Expert 100+
P: 598
First, your program produces many errors, the variable, "output", has not been declared, syntax error=no colon in several places, and at least on more. Once you override a method, it no longer exists, unless to call it explicitly (from an instance of MyClass in this class.) Search for method overriding/overloading for a detailed answer like http://blog.thedigitalcatonline.com/...ing-in-python/
2 Weeks Ago #2

P: 7
Thank you for the response and link provided. I apologize because the code entered in the post was just example code. It does not have functionality. I'm trying to better understand the significance of subclasses and what can be done with them. The link helped clarify some things.
2 Weeks Ago #3

Post your reply

Sign in to post your reply or Sign up for a free account.