I have a class Parent
:
class Parent:
def __init__(self, foo):
self.foo = foo
I then have another class Child
which extends Parent
. But I want Child
to take a pre-existing instance of parent
and use this as the parent to inherit from (instead of creating a new instance of Parent
with the same constructor parameters).
class Child(Parent):
def __init__(self, parent_instance):
""" Do something with parent_instance to set this as the parent instance """
def get_foo(self):
return self.foo
Then I would ideally be able to do:
p = Parent("bar")
c = Child(p)
print(c.get_foo()) # prints "bar"