0

Simple question really, addressed to Python 3 usage: How do I make the parent work using only the child instance c?

class Parent:
    def work(self):
        print("Parent working")

class Child(Parent):
    def work(self):
        print("Child working")
        
c = Child()
c.work()

I do not want to modify my Child class as it is from an outside library. I'm looking for something like this:

>>> c.super().work()  # can't do that as super is not a Child method
Parent working
ceprio
  • 373
  • 3
  • 10

1 Answers1

0

To call super on an object outside of a method call you need to use the 2 argument form of super where you pass the class and the object

super(Child, c).work()

If you do not know the object's class you can use type to get it

super(type(c), c).work()
Iain Shelvington
  • 31,030
  • 3
  • 31
  • 50