class Node(object): def __init__(self, path, inode=MyStat(), children=): self.path = path self.inode = inode self.children = children
To a newbie like me, this looks perfectly fine. If no inode is passed in create an instance of MyStat(), if no children are passed in create an empty list. Well guess what! That’s not how python works with lists. If you do what I did above the children list is shared! Imagine my horror when each Node has a reference to ALL of the children of the other Nodes. EEK! A few minutes of googling and I found this page:
4.7.1 Default Argument Values.
I changed the constructor of the Node class to be as follows:
def __init__(self, path, inode=MyStat(), children=None): self.path = path self.inode = inode if children is None: self.children =  else: self.children = children
This fixed my problem.