networkx.readwrite.sparse6.write_sparse6¶
-
write_sparse6(G, path, nodes=None, header=True)[source]¶ Write graph G to given path in sparse6 format.
- Parameters
- Raises
NetworkXError – If the graph is directed
Examples
You can write a sparse6 file by giving the path to the file:
>>> import tempfile >>> with tempfile.NamedTemporaryFile() as f: ... nx.write_sparse6(nx.path_graph(2), f.name) ... print(f.read()) b'>>sparse6<<:An\n'
You can also write a sparse6 file by giving an open file-like object:
>>> with tempfile.NamedTemporaryFile() as f: ... nx.write_sparse6(nx.path_graph(2), f) ... _ = f.seek(0) ... print(f.read()) b'>>sparse6<<:An\n'
See also
Notes
The format does not support edge or node labels.
References
- 1
Sparse6 specification <http://users.cecs.anu.edu.au/~bdm/data/formats.html>