rustworkx.PyDAG.read_edge_list#

static PyDAG.read_edge_list(path, /, comment=None, deliminator=None, labels=False)#

Read an edge list file and create a new PyDiGraph object from the contents

The expected format for the edge list file is a line seperated list of deliminated node ids. If there are more than 3 elements on a line the 3rd on will be treated as a string weight for the edge

Parameters:
  • path (str) – The path of the file to open

  • comment (str) – Optional character to use as a comment by default there are no comment characters

  • deliminator (str) – Optional character to use as a deliminator by default any whitespace will be used

  • labels (bool) – If set to True the first two separated fields will be treated as string labels uniquely identifying a node instead of node indices.

For example:

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)
../_images/rustworkx.PyDAG.read_edge_list_0_0.png