The following code allows me to create a directory if it does not already exist.
dir = \'path_to_my_folder\' if not os.path.exists(dir): os.makedirs(dir)
os.path.exists(dir) check is recommended but can be avoided by using ignore_errors
os.path.exists(dir)
ignore_errors
dir = 'path_to_my_folder' shutil.rmtree(dir, ignore_errors=True) os.makedirs(dir)