def yield_tree_attrs(tree, attr_name, children_attr_name):
    """Yield specific attributes in objects in a tree.

    Parameters
    ==========
    tree (any python object)
        object which might contain children objects.
    attr_name (string)
        name of attribute whose value you want to yield
        for each object of the tree.
    children_attr_name (string)
        name of attribute wherein to find more children.
    """
    ### yield attributes from each children, if there are
    ### children

    try:
        children = getattr(tree, children_attr_name)

    except AttributeError:
        pass

    else:

        for child in children:

            yield from yield_tree_attrs(child, attr_name, children_attr_name)

    ### yield attribute from the object itself, if it has
    ### such attribute

    try:
        value = getattr(tree, attr_name)
    except AttributeError:
        pass
    else:
        yield value
Yield specific attributes in objects in a tree.

    Parameters
    ==========
    tree (any python object)
        object which might contain children objects.
    attr_name (string)
        name of attribute whose value you want to yield
        for each object of the tree.
    children_attr_name (string)
        name of attribute wherein to find more children.
    
nodezator/ourstdlibs/treeutils.py