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


Python Tree.display方法代码示例

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


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

示例1: Tree

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import display [as 别名]
__author__ = 'Suraj'

from tree import Tree

tree = Tree()
tree.display()
tree.userTurn()
tree.display()




开发者ID:uchihaitachi24,项目名称:TTT,代码行数:10,代码来源:TicTacToe.py

示例2: dict

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import display [as 别名]
        tree[parent]
    except KeyError:
        tree.add_node(parent)
        
    try:
        tree[child]
    except KeyError:
        tree.add_node(child)
        
    tree[parent].add_child(child)
    tree[child].add_parent(parent)


query = ("SELECT id, name FROM imm_web")
cursor.execute(query)
id_name_dict = {}
for (id, name) in cursor:
    id_name_dict[id] = name

tree.display(1)
return_info = dict()
print("***** DEPTH-FIRST ITERATION *****")
for node in tree.traverse(1):
    print(str(node) + ", " + id_name_dict[node] + ", " + str(tree[node].parent))
    return_info[node] = [id_name_dict[node], tree[node].parent]
print("***** BREADTH-FIRST ITERATION *****")
for node in tree.traverse(1, mode=_BREADTH):
    print(str(node) + ", " + id_name_dict[node])

cursor.close()
cnx.close()
开发者ID:earage,项目名称:nodePresent,代码行数:33,代码来源:testItem.py

示例3: test_node

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import display [as 别名]

#.........这里部分代码省略.........
        
    dim = ["src_ip","dst_ip"]
    child = Node.create_children_tree(dim,common_prefix,node1,node2,[node1,node2])

    
    if IPv4Address.IntToDottedIP(common_prefix["src_ip"].get_prefix()) == "108.64.64.0" and common_prefix["src_ip"].get_prefix_len() == 19 and IPv4Address.IntToDottedIP(common_prefix["dst_ip"].get_prefix()) == "108.96.64.0" and common_prefix["dst_ip"].get_prefix_len() == 19:
        print "test nodes common_prefix success"
    else:
        print "test nodes common_prefix ERROR"
        
   
    if child['src_ip'][0]['dst_ip'][0] == node1 and not 1 in child['src_ip'][0]['dst_ip'].keys() and not 0 in child['src_ip'][1]['dst_ip'].keys() and child['src_ip'][1]['dst_ip'][1] == node2:
        print "test nodes create_children success"
    else:
        print "test nodes create_children ERROR"
        

    key = {}
    c = IPv4Address("108.64.77.102",32)
    d = IPv4Address("108.96.88.88",32)
    key["src_ip"] = c
    key["dst_ip"] = d
    
    tt = node1.__class__.__name__

    node2 = globals()[tt](key,20,[])
    
    common_prefix={"src_ip":a.common_prefix(c),"dst_ip":b.common_prefix(d)}
    
    dim = ["src_ip","dst_ip"]
    child = Node.create_children_tree(dim,common_prefix,node1,node2,[node1,node2])

    
    if IPv4Address.IntToDottedIP(common_prefix["src_ip"].get_prefix()) == "108.64.77.102" and common_prefix["src_ip"].get_prefix_len() == 31 and IPv4Address.IntToDottedIP(common_prefix["dst_ip"].get_prefix()) == "108.96.64.0" and common_prefix["dst_ip"].get_prefix_len() == 19:
        print "test nodes common_prefix with artificial split success"
    else:
        print "test nodes common_prefix ERROR"
    
  

    #if child['src_ip'][0]['dst_ip'][0] == node1 and not 1 in child['src_ip'].keys() and child['src_ip'][0]['dst_ip'][1] == node2:
    #    print "test nodes create_children 2 success"
    #else:
    #    print "test nodes create_children 2 ERROR"
    
    tree = Tree(dim)
    if tree.is_empty() == True:
        print "test tree is_empty 1 success"
    else:
        print "test tree is_empty 1 ERROR"
        
    
    nodeAF = create_node("108.64.77.102","108.96.77.88",tree)
    key = {}
    
    if tree.is_empty() == False:
        print "test tree is_empty 2 success"
    else:
        print "test tree is_empty 2 ERROR"
    
    
    node2 = create_node("108.64.77.102","108.96.77.88",tree)

    tree = Tree(dim)
    
    nodeBG = create_node("108.64.88.102","108.96.88.88",tree)
    nodeAF = create_node("108.64.77.102","108.96.77.88",tree)
    nodeAG = create_node("108.64.77.102","108.96.88.88",tree)
    nodeAG2 = create_node("108.64.77.102","108.96.88.88",tree)
    nodeBF = create_node("108.64.88.102","108.96.77.88",tree)
    nodeIF = create_node("108.64.88.130","108.96.77.88",tree)
    """
    explore = tree.get_root().explore_intern(dim,dict_dim,IPv4Address(32,"108.64.88.130"))
    print explore[0]
    print explore[1]
    """

    nodeMN = create_node("202.102.10.10","210.110.0.0",tree)
    print tree.display()
    check_tree(tree)
    
    
    
    
    tree = Tree(dim)
    nodeAF = create_node("108.64.77.102","108.96.77.88",tree)
    nodeBG = create_node("108.64.88.102","108.96.88.88",tree)
    nodeAG = create_node("108.64.77.102","108.96.88.88",tree)
    nodeBF = create_node("108.64.88.102","108.96.77.88",tree)
    nodeIF = create_node("108.64.88.130","108.96.77.88",tree)
    nodeMN = create_node("202.102.10.10","210.110.0.0",tree)
    nodeAG.get_parent().remove_children(nodeAG)
    
    
    if not 1 in nodeAG.get_parent().get_children()['src_ip'][0]['dst_ip'].keys() and nodeAG.get_parent().get_value() == 10:
        print "Test tree remove success"
    else:
        print "Test tree remove ERROR"
    print tree.get_root.preorder()
    print tree.display()
开发者ID:jfrancois,项目名称:mam,代码行数:104,代码来源:multiAggregator.py

示例4: running_groups

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import display [as 别名]
if __name__ == "__main__":
    from running_vms import running_vms
    from running_groups import running_groups
    from vm_snaps import vm_snaps
    from tree import Tree
    
    rgs = running_groups()
    rg = rgs.pop()
    
    snaps_tree = Tree()
    snaps_tree.add_node(rg, None)
    
    for vm in running_vms():
        vm_snaps(vm, snaps_tree, rg)
    
    snaps_tree.display(rg)
开发者ID:tjtaill,项目名称:Scripts,代码行数:18,代码来源:group_snaps.py

示例5: Copyright

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import display [as 别名]
# Copyright (C) by Brett Kromkamp 2011-2014 ([email protected])
# You Programming (http://www.youprogramming.com)
# May 03, 2014

from tree import Tree

(_ROOT, _DEPTH, _BREADTH) = range(3)

tree = Tree()

tree.add_node("Harry")  # root node
tree.add_node("Jane", "Harry")
tree.add_node("Bill", "Harry")
tree.add_node("Joe", "Jane")
tree.add_node("Diane", "Jane")
tree.add_node("George", "Diane")
tree.add_node("Mary", "Diane")
tree.add_node("Jill", "George")
tree.add_node("Carol", "Jill")
tree.add_node("Grace", "Bill")
tree.add_node("Mark", "Jane")

tree.display("Harry")
print("***** DEPTH-FIRST ITERATION *****")
for node in tree.traverse("Harry"):
    print(node)
print("***** BREADTH-FIRST ITERATION *****")
for node in tree.traverse("Harry", mode=_BREADTH):
    print(node)
开发者ID:robertowtr,项目名称:SegurancaAuditoria,代码行数:31,代码来源:app.py

示例6: importData

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import display [as 别名]
def importData(fname, displayTree=False, colSep=',', headerLine=False, verbose=False):
    """
    Import tree data from a CSV (text) file or list. 

    The data should be in the following format:
    node_ID_number,node_parent_ID_number,data_item1,data_item2,...,data_itemN\n

    The separator can, optionally, be a character other than ","

    The root node must have a parent id of 0 and normally should also have an index of 1

    From MATLAB one can produce tree structures and dump data in the correct format
    using https://github.com/raacampbell13/matlab-tree and the tree.dumptree method

    Inputs:
    fname - if a string, importData assumes it is a file name and tries to load the tree from file.
            if it is a list, importData assumes that each line is a CSV data line and tries to 
            convert to a tree.        
    displayTree - if True the tree is printed to standard output after creation
    colSep - the data separator, a comma by default.
    headerLine - if True, the first line is stripped off and considered to be the column headings.
                headerLine can also be a CSV string or a list that defines the column headings. Must have the
                same number of columns as the rest of the file.
    verbose - prints diagnositic info to screen if true
    """



    if verbose:
        print "tree.importData importing file %s" % fname

    #Error check
    if isinstance(fname,str):
        if os.path.exists(fname)==False:
            print "Can not find file " + fname
            return

        #Read in data
        fid = open(fname,'r')
        contents = fid.read().split('\n')
        fid.close()

    elif isinstance(fname,list):
        contents=fname #assume that fname is data rather than a file name


    #Get header data if present
    if headerLine==True:
        header = contents.pop(0)
        header = header.rstrip('\n').split(colSep)
    elif isinstance(headerLine,str):
        header = headerLine.rstrip('\n').split(colSep)
    elif isinstance(headerLine,list):
        header = headerLine
    else:
        header = False


    data = []
    for line in contents:
        if len(line)==0:
            continue

        dataLine = line.split(colSep)
        if len(header) !=len(dataLine):
            print "\nTree file appears corrupt! header length is %d but data line length is %d.\ntree.importData is aborting.\n" % (len(header),len(dataLine))
            return False

        theseData = map(int,dataLine[0:2]) #add index and parent to the first two columns

        #Add data to the third column. Either as a list or as a dictionary (if header names were provided)
        if header != False: #add as dictionary
            dataCol = dict()

            for ii in range(len(header)-2):
                ii+=2
                dataCol[header[ii]]=dataTypeFromString.convertString(dataLine[ii])

        else:
            dataCol = dataLine[2:] #add as list of strings


        theseData.append(dataCol) 
        data.append(theseData)

    if verbose:
        print "tree.importData read %d rows of data from %s" % (len(data),fname)


    #Build tree
    tree = Tree()
    tree.add_node(0)
    for thisNode in data:
        tree.add_node(thisNode[0],thisNode[1])
        tree[thisNode[0]].data = thisNode[2]


    #Optionally dump the tree to screen (unlikely to be useful for large trees)
    if displayTree:
        tree.display(0)
#.........这里部分代码省略.........
开发者ID:raacampbell,项目名称:lasagna,代码行数:103,代码来源:tree.py

示例7: print

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import display [as 别名]
    treeOfLife["Fish"].data = 'they swim'
    treeOfLife["Amphibians"].data = 'they croak'
    treeOfLife["Reptiles"].data = 'they stick to walls'
    treeOfLife["Mammals"].data = 'they have udders'


    print "List of nodes:"
    print treeOfLife.nodes.keys()
    print ""

    print "Children of node 'Vertebrates'"
    print treeOfLife.nodes['Vertebrates'].children
    print ""


    print treeOfLife.display('Life')


    print("\n***** Depth-first *****")
    for nodeID in treeOfLife.traverse("Life"):
        print(nodeID)

    print("\n***** Width-first *****")
    for nodeID in treeOfLife.traverse("Life", mode=_WIDTH):
        print(nodeID)
    
    print("\n***** Width-first of all data in vertebrates *****")
    for nodeID in treeOfLife.traverse("Vertebrates", mode=_WIDTH):
        print "%s - %s" % (nodeID, treeOfLife[nodeID].data)

    print "\nLeaves:"
开发者ID:raacampbell,项目名称:lasagna,代码行数:33,代码来源:tree.py

示例8: vm_snaps

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import display [as 别名]
def vm_snaps(vm, snaps_tree, root):
    from collections import deque   
    
    snaps = deque()
    snaps.append(vm.find_snapshot(""))
    snaps_tree.add_node(vm.name, root)
    last_parent = vm.name
    while snaps:
        s = snaps.popleft()
        snaps_tree.add_node(s.name, last_parent)
        last_parent = s.name
        snaps.extend(s.children)

if __name__ == "__main__":
    import sys
    import virtualbox    
    from tree import Tree
    
    sys.coinit_flags = 0   
    vbox = virtualbox.VirtualBox()    
    snaps_tree = Tree()
    vm = vbox.find_machine(sys.argv[1])
    vm_snaps(vm, snaps_tree, None)
    snaps_tree.display(vm.name)

    
开发者ID:tjtaill,项目名称:Scripts,代码行数:26,代码来源:vm_snaps.py


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