code: def open_file(filename, mode="r"):
      """
      Context manager which yields an open file or handle with the given mode
      and closes it if needed afterwards.
  
      Parameters
      ----------
      filename : str or file handle
          File (handle) to open.
      mode: {'r', 'w'}
          Specifies the mode in which the file is opened.
  
      Yields
      ------
          Open file (handle).
  
      """
      # check if we need to open the file
      if isinstance(filename, string_types):
          f = fid = _io.open(filename, mode)
      else:
          f = filename
          fid = None
      # yield an open file handle
      yield f
      # close the file if needed
      if fid:
          fid.close()
  
imports: from __future__ import absolute_import, division, print_function
  import contextlib
  import io
  import numpy
  from .audio import load_audio_file
  from .midi import load_midi, write_midi
  from ..utils import suppress_warnings, string_types
label_desc: Use image node_id 1 for calling a global function with example usage: open_file(filename, mode) without return types