Warning

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

read_sparse6

read_sparse6(path)[source]

Read an undirected graph in sparse6 format from path.

Parameters:path (file or string) – File or filename to write.
Returns:G – If the file contains multple lines then a list of graphs is returned
Return type:Graph/Multigraph or list of Graphs/MultiGraphs
Raises:NetworkXError – If the string is unable to be parsed in sparse6 format

Examples

>>> nx.write_sparse6(nx.Graph([(0,1),(0,1),(0,1)]), 'test.s6')
>>> G = nx.read_sparse6('test.s6')
>>> sorted(G.edges())
[(0, 1)]

References

Sparse6 specification: http://cs.anu.edu.au/~bdm/data/formats.txt