NetworkX

Previous topic

networkx.read_adjlist

Next topic

networkx.read_multiline_adjlist

networkx.write_adjlist

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

Write graph G in single-line adjacency-list format to path.

See read_adjlist for file format details.

Examples

>>> G=nx.path_graph(4)
>>> nx.write_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_adjlist(G, fh)

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

>>> nx.write_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”,encoding=’utf=8’) # use utf-8 encoding nx.write_adjlist(G,fh)

Does not handle edge data. Use ‘write_edgelist’ or ‘write_multiline_adjlist’