docs: def to_file(data, filename_or_file_object):
      """
      Write ``data`` to a file specified by either filename of the file or an opened :class:`file` buffer.
  
      :param data: Object to write to file
      :param filename_or_file_object: filename/or opened file buffer to write to
      :type filename_or_file_object: basestring|file
      """
      if isinstance(filename_or_file_object, basestring):
          file_ = open(filename_or_file_object, 'w')
          we_opened = True
      else:
          file_ = filename_or_file_object
          we_opened = False
  
      try:
          file_.write(dump(data))
      finally:
          if we_opened:
              file_.close()