code: def _write_graph_to_pickle_file(graph, fname=None, version=-1):
      """Saves the graph in Python pickled format
  
      @param fname: the name of the file or a stream to save to. If
        C{None}, saves the graph to a string and returns the string.
      @param version: pickle protocol version to be used. If -1, uses
        the highest protocol available
      @return: C{None} if the graph was saved successfully to the
        given file, or a string if C{fname} was C{None}.
      """
      import pickle as pickle
  
      if fname is None:
          return pickle.dumps(graph, version)
      if not hasattr(fname, "write"):
          file_was_opened = True
          fname = open(fname, "wb")
      else:
          file_was_opened = False
      result = pickle.dump(graph, fname, version)
      if file_was_opened:
          fname.close()
      return result
  
file_path: python-igraph/src/igraph/io/files.py
imports: import gzip
  import os
  from shutil import copyfileobj
  from warnings import warn
  from igraph._igraph import GraphBase
  from igraph.utils import named_temporary_file
label_desc: Use image node_id 11 for calling a global function with example usage: _write_graph_to_pickle_file(graph, fname, version) and returns: result, pickle