def assure_path_exists(path): dir = os.path.dirname(path) if not os.path.exists(dir): os.makedirs(dir)first line define python function/module assure_path_exists, which take one argument "path" of file or directory.
second line, ensure path contain directory only. it strips filename, if there is any.
third line, checks for whether this path (pointed by dir), exists or not
forth line, if path pointed by dir not exists, we create that path through os.makedirs
Done!!!
No comments:
Post a Comment