NetworkX

Previous topic

networkx.read_edgelist

Next topic

GML

Quick search

networkx.write_edgelist

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

Write graph as a list of edges.

Parameters:

G : graph

A networkx graph

path : file or string

File or filename to write. Filenames ending in .gz or .bz2 will be compressed.

comments : string, optional

The character used to indicate the start of a comment

delimiter : string, optional

The string uses to separate values. The default is whitespace.

Notes

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.edgelist",'w',encoding='utf=8') # utf-8 encoding
>>> nx.write_edgelist(G,fh)

Examples

>>> G=nx.path_graph(4)
>>> nx.write_edgelist(G, "test.edgelist")
>>> fh=open("test.edgelist",'w')
>>> nx.write_edgelist(G,fh)
>>> nx.write_edgelist(G, "test.edgelist.gz")