Generate a single entry of the graph
Gin GML format.
- G (NetworkX graph) – The graph to be converted to GML.
- 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 a
ValueErrorto indicate that. Default value: None.
lines – Lines of GML data. Newlines are not appended.
generator of strings
stringizercannot convert a value into a string, or the value to convert is not a string while
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
destringizer, the code is capable of handling
listdata as required by the GML specification. For other data types, you need to explicitly supply a
For additional documentation on the GML file format, please see the GML website.
See the module docstring
networkx.readwrite.gmlfor more details.
>>> G = nx.Graph() >>> G.add_node("1") >>> print("\n".join(nx.generate_gml(G))) graph [ node [ id 0 label "1" ] ] >>> G = nx.OrderedMultiGraph([("a", "b"), ("a", "b")]) >>> print("\n".join(nx.generate_gml(G))) graph [ multigraph 1 node [ id 0 label "a" ] node [ id 1 label "b" ] edge [ source 0 target 1 key 0 ] edge [ source 0 target 1 key 1 ] ]