rustworkx.PyDAG.read_edge_list#
- static PyDAG.read_edge_list(path, /, comment=None, deliminator=None, labels=False)#
从边列表文件读取内容并创建一个新的PyDiGraph对象
期望的边列表文件格式是分隔符分隔的节点ID组成的行分隔列表。如果一行中有超过3个元素,第三个将被视为边的字符串权重
- Parameters:
path (str) – 待打开文件的路径
comment (str) – 可选字符,默认用作注释字符,默认情况下没有注释字符
deliminator (str) – 可选字符,用作分隔符, 默认情况下会使用任何空白字符
labels (bool) – 如果设置为
True,则前两个分离字段 将被视为唯一标识节点的字符串标签, 而非节点索引。
例如:
import tempfile import rustworkx as rx from rustworkx.visualization import mpl_draw with tempfile.NamedTemporaryFile('wt') as fd: path = fd.name fd.write('0 1\n') fd.write('0 2\n') fd.write('0 3\n') fd.write('1 2\n') fd.write('2 3\n') fd.flush() graph = rx.PyDiGraph.read_edge_list(path) mpl_draw(graph)