def traverse(node):
g.es(node.h,color='green')
if node.hasChildren():
for sub_node in node.children_iter():
traverse(sub_node)
This function will successfully output the present node and its recursive children when traverse(c.p) is executed.
I've tried to throw some yield statements in but i'm just not getting the result I'm looking for, if I put the yield in the for loop it's only getting the top level children.
I think my grasp of generators just isn't what I thought it was, or maybe recursion with generators is more complicated than I thought.
Any insight would be appreciated.
I'm trying to create a generator which traverses a node and its children but I'm having trouble, this is what I have as a non-generator:
I wonder if adding a "generators" section to Leo scripting documentation would be useful?
Now I really feel stupid!