本文整理汇总了Python中treelib.Tree.edgeAttrs方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.edgeAttrs方法的具体用法?Python Tree.edgeAttrs怎么用?Python Tree.edgeAttrs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类treelib.Tree
的用法示例。
在下文中一共展示了Tree.edgeAttrs方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load
# 需要导入模块: from treelib import Tree [as 别名]
# 或者: from treelib.Tree import edgeAttrs [as 别名]
def load(path):
gtype = None
graph = None
nodes = []
#TEMP: LOAD FILE FROM PATH#
file = open(path,"r",0)
#TEMP#
gtype = file.next()
gtype = int(gtype)
if (gtype == 0):
graph = Tree()
nodes = []
if (gtype == 1):
graph = digraph()
graph.nodeAttrs = []
graph.edgeAttrs = []
for linenum,line in enumerate(file):
if (linenum == 0):
parts = line.split()
nodeAttrs = parts[1].split(';')
numNodeAttrs = nodeAttrs.pop(0)
graph.nodeAttrs = nodeAttrs
continue
if (linenum == 1):
for node in line.split():
tokens = node.split(';')
index = tokens.pop(0)
if (isInt(index)):
index = int(index)
if (gtype == 0):
nodes.append(Node(identifier=index,data=tokens))
if (index == 0):
graph.add_node(nodes[0])
if (gtype == 1):
graph.add_node(index, attrs=tokens)
continue
if (linenum == 2):
if (gtype == 0):
numEdges = int(line)
if (gtype == 1):
parts = line.split()
lineAttrs = parts[1].split(';')
numLineAttrs = lineAttrs.pop(0)
continue
if (linenum > 2):
#CHECK THAT PARTS ARE INT
parts = line.split()
tail = int(parts[0])
head = int(parts[1])
if (gtype == 0):
graph.add_node(nodes[head],tail)
if (gtype == 1):
attributes = parts[2].split(';')
weight = attributes.pop(0)
graph.add_edge((tail,head),weight,attrs=attributes)
return graph