Check os.makedirsos.makedirs: (It makes sure the complete path exists.)
To handle the fact the directory might exist, catch OSErrorOSError.
(If exist_okexist_ok is FalseFalse (the default), an OSErrorOSError is raised if the target directory already exists.)
import os
try:
os.makedirs('./path/to/somewhere')
except OSError:
pass