code: def safe_open(filename, *args, **kwargs):
    
    safe_mkdir(os.path.dirname(filename))
    return open(filename, *args, **kwargs)
docs: Safely open a file.
  
    ``safe_open`` ensures that the directory components leading up the
    specified file have been created first.