class Node:
"""
General tree structure
"""
def __init__(self,obj="",prof=1,call_me=None):
self.obj = obj
self.childs = []
self.prof = prof
self.call_me = None
def __call__(self):
if self.call_me:
self.call_me()
else:
return "I m a simple node"
def add_child(self,child):
if not isinstance(child,Node):
raise "child is not a Node"
if child.obj in [my_childs.obj for my_childs in self.childs]:
return
self.childs.append(child)
def is_atom(self):
return bool(len(self.childs)==0)
def parcours_prof_gauche(node):
results = [node()]
if not node.is_atom():
for child in node.childs:
results.append(parcours_prof_gauche(child))
return results