I'm new to inheritance and all of the previous discussions about inheritance and Python's super() function are a bit over my head. I currently use the following code to update a parent object's value.
#!/usr/bin/env python
# test.py
class Master(object):
mydata = []
def __init__(self):
s1 = Sub1(self)
s2 = Sub2(self)
class Sub1(object):
def __init__(self,p):
self.p = p
self.p.mydata.append(1)
class Sub2(object):
def __init__(self,p):
self.p = p
self.p.mydata.append(2)
if __name__ == "__main__":
m = Master()
print m.mydata
This command line returns as follows:
user@host:~$ ./test.py
[1, 2]
Is there a better way to do this with super() instead of passing the the "self" reference to the child?