This documents the development version of NetworkX. Documentation for the current release can be found here.
write_graph6(G, path, nodes=None, header=True)¶
Write a simple undirected graph to a path in graph6 format.
- GGraph (undirected)
The path naming the file to which to write the graph.
- nodes: list or iterable
Nodes are labeled 0…n-1 in the order provided. If None the ordering given by
- header: bool
If True add ‘>>graph6<<’ string to head of data
If the graph is directed or is a multigraph.
If the graph has at least
2 ** 36nodes; the graph6 format is only defined for graphs of order less than
2 ** 36.
The function writes a newline character after writing the encoding of the graph.
The format does not support edge or node labels, parallel edges or self loops. If self loops are present they are silently ignored.
Graph6 specification <http://users.cecs.anu.edu.au/~bdm/data/formats.html>
You can write a graph6 file by giving the path to a file:
>>> import tempfile >>> with tempfile.NamedTemporaryFile() as f: ... nx.write_graph6(nx.path_graph(2), f.name) ... _ = f.seek(0) ... print(f.read()) b'>>graph6<<A_\n'