os.mkdir raises a generic exception if an error occurs, but typically you need to ignore preexisting directory errors. Here's how to ignore them:
import os, errno, sys
myPath = "/path/to/dir"
try:
os.mkdir(myPath)
except Exception, e:
code, st = e
if code != errno.EEXIST:
st = "Error creating directory '%s': %s" % (myPath, str(e))
sys.exit(1)
directoryexceptionslanguagesmkdirosprogrammingpython