How to link parent and children to each other?
问题 Having two simple classes; one with only parent attribute, and one with both parent and children attributes. This means that the one with both parent and children inherits from the one with only parent . Here's the class with only parent attribute. Let's call it Child since it can only be a child, not a parent. I'll use a method set_parent() to make it more clear, but I would use a setter in my actual code. class Child(object): def __init__(self, parent=None): self.__parent = None self.set