NetworkX

Previous topic

networkx.read_multiline_adjlist

Next topic

Edge List

Quick search

networkx.write_multiline_adjlist

write_multiline_adjlist(G, path, delimiter=' ', comments='#')

Write the graph G in multiline adjacency list format to the file or file handle path.

See read_multiline_adjlist for file format details.

Examples

>>> G=nx.path_graph(4)
>>> nx.write_multiline_adjlist(G,"test.adjlist")

path can be a filehandle or a string with the name of the file.

>>> fh=open("test.adjlist",'w')
>>> nx.write_multiline_adjlist(G,fh)

Filenames ending in .gz or .bz2 will be compressed.

>>> nx.write_multiline_adjlist(G,"test.adjlist.gz")

The file will use the default text encoding on your system. It is possible to write files in other encodings by opening the file with the codecs module. See doc/examples/unicode.py for hints.

>>> import codecs
>>> fh=codecs.open("test.adjlist",'w',encoding='utf=8') # utf-8 encoding
>>> nx.write_multiline_adjlist(G,fh)