Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ObjectA(object):
- '''Might have a parent and might have an array of children'''
- def __init__(self, parent=None):
- self.children = []
- if parent:
- parent.add_child(self)
- self.parent = parent
- def is_parent(self):
- if self.children:
- return True
- else:
- return False
- def add_child(self, child):
- self.children.append(child)
- child.parent = self
- def get_parent_array(self):
- if self.parent:
- return self.parent.children
- else:
- return None
- if __name__ == "__main__":
- p = ObjectA()
- c1 = ObjectA(parent=p)
- c2 = ObjectA(parent=p)
- c3 = ObjectA(parent=p)
- print(p.children)
Advertisement
Add Comment
Please, Sign In to add comment