I'm still quite new to Python but I wanted to know if I could, instantiate a child object using an instantiated parent object. Something like this:
class Parent:
def __init__(self, a):
self.a = a
def parent_function(self):
print self.a
class Child(Parent):
def __init__(self, parent, b):
self.parent = parent
self.b = b
def child_function(self):
print b
parent = Parent("a")
parent_2 = Parent("x")
child = Child(parent, "b")
child.parent_function()
child.child_function()
parent.a = "c"
child.parent_function()
Output:
a
b
c
To hopefully be a little clearer, I would like to inherit the functions and instance variables of an instantiated parent class object in a child class. I know I could make a static/instance variable in the child class that points to the specific parent object I would like to "inherit", but I wanted to know if there was a prettier way to do it