def _traverse(node):
    try:
        for leaf in node.children:
            for leaflet in _traverse(leaf):
                yield leaflet
    except AttributeError:
        pass
    yield node
Generator to traverse a tree accessing the nodes' children
dataset/ETHPy150Open enthought/mayavi/mayavi/tools/tools.py/_traverse