networkx.readwrite.gml.write_gml¶
-
write_gml(G, path, stringizer=None)[source]¶ Write a graph
Gin GML format to the file or file handlepath.Parameters: - G (NetworkX graph) – The graph to be converted to GML.
- path (filename or filehandle) – The filename or filehandle to write. Files whose names end with .gz or .bz2 will be compressed.
- stringizer (callable, optional) – A
stringizerwhich converts non-int/non-float/non-dict values into strings. If it cannot convert a value into a string, it should raise aValueErrorto indicate that. Default value: None.
Raises: NetworkXError– Ifstringizercannot convert a value into a string, or the value to convert is not a string whilestringizeris None.See also
Notes
Graph attributes named ‘directed’, ‘multigraph’, ‘node’ or ‘edge’, node attributes named ‘id’ or ‘label’, edge attributes named ‘source’ or ‘target’ (or ‘key’ if
Gis a multigraph) are ignored because these attribute names are used to encode the graph structure.GML files are stored using a 7-bit ASCII encoding with any extended ASCII characters (iso8859-1) appearing as HTML character entities. Without specifying a
stringizer/destringizer, the code is capable of handlingint/float/str/dict/listdata as required by the GML specification. For other data types, you need to explicitly supply astringizer/destringizer.Note that while we allow non-standard GML to be read from a file, we make sure to write GML format. In particular, underscores are not allowed in attribute names. For additional documentation on the GML file format, please see the GML website.
See the module docstring
networkx.readwrite.gmlfor more details.Examples
>>> G = nx.path_graph(4) >>> nx.write_gml(G, "test.gml")
Filenames ending in .gz or .bz2 will be compressed.
>>> nx.write_gml(G, "test.gml.gz")