mkdir -p gives you an error if the file already exists:
$ touch /tmp/foo
$ mkdir -p /tmp/foo
mkdir: cannot create directory `/tmp/foo': File exists
You can try the full code as following
import os
def mkdirp(directory):
if not os.path.isdir(directory):
os.makedirs(directory)