rustworkx.PyDiGraph.write_edge_list#
- PyDiGraph.write_edge_list(path, /, deliminator=None, weight_fn=None)#
将PyDiGraph对象的边列表写入文件
- Parameters:
path (str) – 指定输出文件的写入路径
deliminator (str) – 可选字符,用作分隔符 如果未指定,则使用
" "。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
TypeErrorwill 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