read_graph6

read_graph6(path)[source]

Read simple undirected graphs in graph6 format from path.

Parameters
pathfile or string

File or filename to write.

Returns
GGraph or list of Graphs

If the file contains multiple lines then a list of graphs is returned

Raises
NetworkXError

If the string is unable to be parsed in graph6 format

References

1

Graph6 specification <http://users.cecs.anu.edu.au/~bdm/data/formats.html>

Examples

You can read a graph6 file by giving the path to the file:

>>> import tempfile
>>> with tempfile.NamedTemporaryFile() as f:
...     _ = f.write(b">>graph6<<A_\n")
...     _ = f.seek(0)
...     G = nx.read_graph6(f.name)
>>> list(G.edges())
[(0, 1)]

You can also read a graph6 file by giving an open file-like object:

>>> import tempfile
>>> with tempfile.NamedTemporaryFile() as f:
...     _ = f.write(b">>graph6<<A_\n")
...     _ = f.seek(0)
...     G = nx.read_graph6(f)
>>> list(G.edges())
[(0, 1)]