code: def write_gml(G, path, stringizer=None):
      """Write a graph `G` in GML format to the file or file handle `path`.
  
      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 `stringizer` which converts non-int/non-float/non-dict values into
          strings. If it cannot convert a value into a string, it should raise a
          `ValueError` to indicate that. Default value: None.
  
      Raises
      ------
      NetworkXError
          If `stringizer` cannot convert a value into a string, or the value to
          convert is not a string while `stringizer` is None.
  
      See Also
      --------
      read_gml, generate_gml
      literal_stringizer
  
      Notes
      -----
      Graph attributes named 'directed', 'multigraph', 'node' or
      'edge', node attributes named 'id' or 'label', edge attributes
      named 'source' or 'target' (or 'key' if `G` is 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
      writing `int`/`float`/`str`/`dict`/`list` data as required by the GML
      specification.  For writing other data types, and for reading data other
      than `str` you need to explicitly supply a `stringizer`/`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 url <https://web.archive.org/web/20190207140002/http://www.fim.uni-passau.de/index.php?id=17297&L=1>`_.
  
      See the module docstring :mod:`networkx.readwrite.gml` for 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")
      """
      for line in generate_gml(G, stringizer):
          path.write((line + "\n").encode("ascii"))
  
imports: import html.entities
  import re
  import warnings
  from ast import literal_eval
  from collections import defaultdict
  from enum import Enum
  from io import StringIO
  from typing import Any, NamedTuple
  import networkx
  from networkx.exception import NetworkXError
  from networkx.utils import open_file
label_desc: Use image node_id 9 for calling a global function with example usage: write_gml(G, path, stringizer) without return types