rustworkx.PyDiGraph.write_edge_list#
- PyDiGraph.write_edge_list(path, /, deliminator=None, weight_fn=None)#
Write an edge list file from the PyDiGraph object
- Parameters:
path (str) – The path to write the output file to
deliminator (str) – The optional character to use as a deliminator if not specified
" "
is used.weight_fn (callable) –
- An optional callback function that will be
passed an edge’s data payload/weight object and is expected to return a string (a
TypeError
will be raised if it doesn’t return a string). If specified the weight in the output file for each edge will be set to the returned string.
For example:
import os import tempfile import rustworkx as rx graph = rx.generators.directed_path_graph(5) path = os.path.join(tempfile.gettempdir(), "edge_list") graph.write_edge_list(path, deliminator=',') # Print file contents with open(path, 'rt') as edge_file: print(edge_file.read())
0,1 1,2 2,3 3,4