code: def __create_output_dir(base_dir):
      
      root, tail = os.path.split(base_dir)
      dir = None
      if tail:
          if base_dir.endswith('/'):
              dir = base_dir
          else:
              dir = root
      else:
          if base_dir.endswith('/'):
              dir = base_dir
      
      if dir and not os.path.isdir(dir):
          os.makedirs(dir)
docs: Ensure that the output directory base_dir exists.