code: def _ensure_filepath(filename):
          
  
          filepath = os.path.dirname(filename)
          if not os.path.exists(filepath):
              os.makedirs(filepath)
docs: Ensure that the directory exists before trying to write to the file.