In [1]:
from platform import python_version

python_version()
Out[1]:
'3.6.9'
In [2]:
import os
import shutil

Create directory if not exists

In [ ]:
new_directory_path = "/path/to/new/directory"

if not os.path.exists(new_directory_path):
    os.mkdir(new_directory_path)

Mkdir -p behaviour

In [ ]:
new_directory_path = "/path/to/new/directory"

if not os.path.exists(new_directory_path):
    os.makedirs(new_directory_path)

Delete directory

Including subdirectories, if they exist!

foo
└── bar
    ├── baz
    │   └── some-other-file.txt
    └── some-file.txt
In [ ]:
import shutil

directory_path_to_remove = "/path/to/foo/"

if os.path.exists(directory_path_to_remove):
    shutil.rmtree(directory_path_to_remove)