Write the graph G in GML format to the file or file handle path.
Parameters: | path : filename or filehandle
|
---|
Notes
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.
>>> G=nx.path_graph(4)
>>> 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).
For nested attributes for graphs, nodes, and edges you should use dicts for the value of the attribute.
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")