Python subclass function call

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • c0d3rX
    New Member
    • Nov 2018
    • 7

    Python subclass function call

    My questions is regarding subclasses in Python.

    For example, if I have the following code.

    Code:
    class Myclass:
          def __init__(self, input)
              self.input = input
    
          def function(self, input)
              return output
    
    class MySubclass(Myclass)
          def function(self, input)
              return output
    The question is how would you access the function in the sub class as opposed to the one in the base class?
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    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/

    Comment

    • c0d3rX
      New Member
      • Nov 2018
      • 7

      #3
      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.

      Comment

      Working...