code: def _save_history_to_file(history, path, size=-1):
          
          if size == 0:
              return
          if size > 0:
              history = history[-size:]
          directory = os.path.dirname(path)
          if not os.path.exists(directory):
              os.makedirs(directory)
          # Write linewise to avoid building a large string in menory.
          with codecs.open(path, 'w', encoding='utf-8') as histfile:
              for line in history:
                  histfile.write(line)
                  histfile.write('\n')
docs: Save a history list to a file for later loading (possibly in another
          session).
  
          :param history: the history list to save
          :type history: list(str)
          :param path: the path to the file where to save the history
          :param size: the number of lines to save (0 means no lines, < 0 means
              all lines)
          :type size: int
          :type path: str
          :returns: None