code: def write_p2g(G, path, encoding="utf-8"):
      """Write NetworkX graph in p2g format.
  
      Notes
      -----
      This format is meant to be used with directed graphs with
      possible self loops.
      """
      path.write((f"{G.name}\n").encode(encoding))
      path.write((f"{G.order()} {G.size()}\n").encode(encoding))
      nodes = list(G)
      # make dictionary mapping nodes to integers
      nodenumber = dict(zip(nodes, range(len(nodes))))
      for n in nodes:
          path.write((f"{n}\n").encode(encoding))
          for nbr in G.neighbors(n):
              path.write((f"{nodenumber[nbr]} ").encode(encoding))
          path.write("\n".encode(encoding))
  
imports: import networkx
  from networkx.utils import open_file
label_desc: Use image node_id 1 for calling a global function with example usage: write_p2g(G, path, encoding) without return types