Warning

This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.

write_graph6(G, path, nodes=None, header=True)[source]

Write a simple undirected graph to a path in graph6 format.

Parameters: G (Graph (undirected)) path (str) – 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 G.nodes() is used. header (bool) – If True add ‘>>graph6<<’ string to head of data NetworkXNotImplemented – If the graph is directed or is a multigraph. ValueError – If the graph has at least 2 ** 36 nodes; the graph6 format is only defined for graphs of order less than 2 ** 36.

Examples

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)