424,276 Members | 2,626 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,276 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
  1.  
  2. class Myclass:
  3.       def __init__(self, input)
  4.           self.input = input
  5.  
  6.       def function(self, input)
  7.           return output
  8.  
  9. class MySubclass(Myclass)
  10.       def function(self, input)
  11.           return output
  12.  
  13.  
The question is how would you access the function in the sub class as opposed to the one in the base class?
Nov 19 '18 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 604
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/
Nov 19 '18 #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.
Nov 20 '18 #3

Post your reply

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