NetworkX

Previous topic

networkx.read_gml

Next topic

networkx.parse_gml

Quick search

networkx.write_gml

write_gml(G, path)

Write the graph G in GML format to the file or file handle path.

Examples

>>> G=nx.path_graph(4)
>>> nx.write_gml(G,"test.gml")

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

>>> fh=open("test.gml",'w')
>>> nx.write_gml(G,fh)

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

>>> nx.write_gml(G,"test.gml.gz")

The output 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.gml",'w',encoding='iso8859-1')# use iso8859-1
>>> nx.write_gml(G,fh)

GML specifications indicate that the file should only use 7bit ASCII text encoding.iso8859-1 (latin-1).

Only a single level of attributes for graphs, nodes, and edges, is supported.