当前位置: 首页>>代码示例>>Python>>正文


Python Tree.subtree方法代码示例

本文整理汇总了Python中treelib.Tree.subtree方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.subtree方法的具体用法?Python Tree.subtree怎么用?Python Tree.subtree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在treelib.Tree的用法示例。


在下文中一共展示了Tree.subtree方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: compare_actual_folder_with_tree

# 需要导入模块: from treelib import Tree [as 别名]
# 或者: from treelib.Tree import subtree [as 别名]
 def compare_actual_folder_with_tree(self, root: path, tree: Tree):
     root_name = tree.root
     root_path = root.joinpath(root_name)
     print(root_path)
     self.assertTrue(root_path.exists(), "The path {} should exist, but doesn't".format(root_path))
     children = tree.children(root_name)
     for children in children:
         subtree = tree.subtree(children.identifier)
         self.compare_actual_folder_with_tree(root_path, subtree)
开发者ID:phauer,项目名称:integrate-into-music-folder,代码行数:11,代码来源:integrator_tests.py

示例2: create_dummy_download_folder

# 需要导入模块: from treelib import Tree [as 别名]
# 或者: from treelib.Tree import subtree [as 别名]
def create_dummy_download_folder(root: path, tree: Tree) -> path:
    root_name = tree.root
    root_path = root.joinpath(root_name)

    if not root_path.exists():
        print("Creating {}".format(root_path))
        if root_name.endswith(".mp3"):
            root_path.touch()
        else:
            root_path.mkdir()
        time.sleep(0.01)  # sleep to ensure that the created folders don't have the same ctime

    children = tree.children(root_name)
    for children in children:
        subtree = tree.subtree(children.identifier)
        create_dummy_download_folder(root_path, subtree)
    return root_path
开发者ID:phauer,项目名称:integrate-into-music-folder,代码行数:19,代码来源:integrator_tests.py

示例3: crossOver

# 需要导入模块: from treelib import Tree [as 别名]
# 或者: from treelib.Tree import subtree [as 别名]
  def crossOver(individualA, individualB):
    tree = None

    while tree is None or tree.depth(tree.get_node(tree.root)) > TREE_MAX_DEPTH:
      treeA = Tree(tree = individualA.tree, deep=True)
      treeB = Tree(tree = individualB.tree, deep=True)
      regenerate_ids(treeA)
      regenerate_ids(treeB)
      removedNode = random.choice(treeA.all_nodes())
      addedNode = random.choice(treeB.all_nodes())

      addedSubtree = Tree(tree = treeB.subtree(addedNode.identifier), deep=True)

      if treeA.root == removedNode.identifier:
        tree = addedSubtree

      else:
        parent = treeA.parent(removedNode.identifier)
        treeA.remove_subtree(removedNode.identifier)
        treeA.paste(parent.identifier, addedSubtree)
        tree = treeA

    return Individual(tree)
开发者ID:liranr23,项目名称:genersi,代码行数:25,代码来源:individual.py

示例4: print

# 需要导入模块: from treelib import Tree [as 别名]
# 或者: from treelib.Tree import subtree [as 别名]
sep = "-" * 20 + "\n"

print(sep + "Tree of the whole family:")
tree.show(key=lambda x: x.tag, reverse=True)

print(sep + "All family members in DEPTH mode:")
for node in tree.expand_tree(mode=Tree.DEPTH):
    print(tree[node].tag)

print(sep + "All family members without Diane sub-family:")
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:")
开发者ID:Mondego,项目名称:pyreco,代码行数:33,代码来源:allPythonContent.py

示例5: print

# 需要导入模块: from treelib import Tree [as 别名]
# 或者: from treelib.Tree import subtree [as 别名]
print("#"*4 + "Breakdown of out family")
tree.show()
print('\n') 

print("#"*4 + "All family members in DEPTH mode")
for node in tree.expand_tree(mode=Tree.DEPTH):
    print tree[node].tag
print('\n') 

print("#"*4 + "All family members without Diane sub-family")
for node in tree.expand_tree(filter=lambda x: x != 'diane', mode=Tree.DEPTH):
    print tree[node].tag
print('\n') 

print("#"*4 + "Let me introduce Diane family only")
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')
开发者ID:techdragon,项目名称:pyTree-1,代码行数:33,代码来源:family_tree.py


注:本文中的treelib.Tree.subtree方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。