sub_t = tree.subtree('diane') sub_t.show() print('\n') print("#"*4 + "Children of Diane") print tree.is_branch('diane') print('\n') print("#"*4 + "OOhh~ new members enter Jill's family") new_tree = Tree() new_tree.create_node("n1", 1) # root node new_tree.create_node("n2", 2, parent=1) new_tree.create_node("n3", 3, parent=1) tree.paste('jill', new_tree) tree.show() print('\n') print("#"*4 + "We are sorry they are gone accidently :(") tree.remove_node(1) tree.show() print('\n') print("#"*4 + "Now Jill moves to live with Grand-x-father Harry") tree.move_node('jill', 'harry') tree.show() print('\n') print("#"*4 + "A big family for George to talk to Grand-x-father Harry") for node in tree.rsearch('george', filter=lambda x: x != 'harry'): print node print('\n')
new_tree.create_node("n1", 1) # root node new_tree.create_node("n2", 2, parent=1) new_tree.create_node("n3", 3, parent=1) tree.paste("jill", new_tree) tree.show() print(sep + "They leave after a while:") tree.remove_node(1) tree.show() print(sep + "Now Jill moves to live with Grand-x-father Harry:") tree.move_node("jill", "harry") tree.show() print(sep + "A big family for George to send message to the oldest Harry:") for node in tree.rsearch("george"): print(tree[node].tag) ########NEW FILE######## __FILENAME__ = folder_tree #!/usr/bin/env python # A file folder scanner contributed by @holger # # You can spicify the scanned folder and file pattern by changing rootPath # and pattern variables # __author__ = "holger" from treelib import tree import fnmatch
tree.show(idhidden=False, filter=lambda x: x.identifier != 'diane') # for node in tree.expand_tree(filter=lambda x: x.identifier != 'diane', mode=Tree.DEPTH): # print tree[node].tag print(sep + "Let me introduce Diane family only:") sub_t = tree.subtree('diane') sub_t.show() print(sep + "Children of Diane") for child in tree.is_branch('diane'): print(tree[child].tag) print(sep + "OOhh~ new members join Jill's family:") new_tree = Tree() new_tree.create_node("n1", 1) # root node new_tree.create_node("n2", 2, parent=1) new_tree.create_node("n3", 3, parent=1) tree.paste('jill', new_tree) tree.show() print(sep + "They leave after a while:") tree.remove_node(1) tree.show() print(sep + "Now Jill moves to live with Grand-x-father Harry:") tree.move_node('jill', 'harry') tree.show() print(sep + "A big family for George to send message to the oldest Harry:") for node in tree.rsearch('george'): print(tree[node].tag)
print tree.is_branch('diane') print('\n') print("#"*4 + "OOhh~ new members enter Jill's family") new_tree = Tree() new_tree.create_node("n1", 1) # root node new_tree.create_node("n2", 2, parent=1) new_tree.create_node("n3", 3, parent=1) tree.paste('jill', new_tree) tree.show() print('\n') print("#"*4 + "We are sorry they are gone accidently :(") tree.remove_node(1) tree.show() print('\n') print("#"*4 + "Now Jill moves to live with Grand-x-father Harry") tree.move_node('jill', 'harry') tree.show() print('\n') print("#"*4 + "A big family for George to talk to Grand-x-father Harry") for node in tree.rsearch('george', filter=lambda x: x.identifier != 'harry'): print node print('harry') print('\n')
new_tree.create_node("n1", 1) # root node new_tree.create_node("n2", 2, parent=1) new_tree.create_node("n3", 3, parent=1) tree.paste('jill', new_tree) tree.show() print(sep + "They leave after a while:") tree.remove_node(1) tree.show() print(sep + "Now Jill moves to live with Grand-x-father Harry:") tree.move_node('jill', 'harry') tree.show() print(sep + "A big family for George to send message to the oldest Harry:") for node in tree.rsearch('george'): print(tree[node].tag) ########NEW FILE######## __FILENAME__ = folder_tree #!/usr/bin/env python # A file folder scanner contributed by @holger # # You can spicify the scanned folder and file pattern by changing rootPath # and pattern variables # __author__ = 'holger' from treelib import tree import fnmatch
print ("\n") print ("#" * 4 + "OOhh~ new members enter Jill's family") new_tree = Tree() new_tree.create_node("n1", 1) # root node new_tree.create_node("n2", 2, parent=1) new_tree.create_node("n3", 3, parent=1) tree.paste("jill", new_tree) tree.show() print ("\n") print ("#" * 4 + "We are sorry they are gone accidently :(") tree.remove_node(1) tree.show() print ("\n") print ("#" * 4 + "Now Jill moves to live with Grand-x-father Harry") tree.move_node("jill", "harry") tree.show() print ("\n") print ("#" * 4 + "A big family for George to talk to Grand-x-father Harry") for node in tree.rsearch("george", filter=lambda x: x.identifier != "harry"): print node print ("harry") print ("\n")
def _get_ancestors_from_tree(node_identifier: str, tree: Tree) -> Set[str]: ancestors = { node_identifier for node_identifier in tree.rsearch(node_identifier) } return ancestors