I'm trying to make a tree that has a recursive 'printAll' method.
My code is:
class Node(object):
def __init__(self, children=[], tag=None):
self.children = children
self.tag = tag
def appendChild(self, child):
self.children.append(child)
def getChildren(self):
return self.children
def printAll(self):
print self.getChildren()
for child in self.children:
child.printAll()
And when I run it I get this: "maximum recursion depth exceeded while calling a Python object".
I'm guessing it has something to do with passing the top level scope down to the child when calling the child's printAll() method, causing an infinite loop. Any help is much appreciated.