code: def write_pajek(G, path, encoding="UTF-8"):
      """Write graph in Pajek format to path.
  
      Parameters
      ----------
      G : graph
         A Networkx graph
      path : file or string
         File or filename to write.
         Filenames ending in .gz or .bz2 will be compressed.
  
      Examples
      --------
      >>> G = nx.path_graph(4)
      >>> nx.write_pajek(G, "test.net")
  
      Warnings
      --------
      Optional node attributes and edge attributes must be non-empty strings.
      Otherwise it will not be written into the file. You will need to
      convert those attributes to strings if you want to keep them.
  
      References
      ----------
      See http://vlado.fmf.uni-lj.si/pub/networks/pajek/doc/draweps.htm
      for format information.
      """
      for line in generate_pajek(G):
          line += "\n"
          path.write(line.encode(encoding))
  
file_path: networkx/networkx/readwrite/pajek.py
imports: import warnings
  import networkx
  from networkx.utils import open_file
label_desc: Use image node_id 2 for calling a global function with example usage: write_pajek(G, path, encoding) without return types