def mkdir_p(newdir):
    'works the way a good mkdir should :)\n        - already exists, silently complete\n        - regular file in the way, raise an exception\n        - parent directory(ies) does not exist, make them as well\n        From: http://code.activestate.com/recipes/82465-a-friendly-mkdir/\n    '
    if os.path.isdir(newdir):
        pass
    elif os.path.isfile(newdir):
        raise OSError("a file with the same name as the desired dir, '{0}', already exists.".format(newdir))
    else:
        (head, tail) = os.path.split(newdir)
        if (head and (not os.path.isdir(head))):
            mkdir_p(head)
        if tail:
            os.mkdir(newdir)
works the way a good mkdir should :)
- already exists, silently complete
- regular file in the way, raise an exception
- parent directory(ies) does not exist, make them as well
From: http://code.activestate.com/recipes/82465-a-friendly-mkdir/
def mkdir_p(newdir):
    'works the way a good mkdir should :)\n        - already exists, silently complete\n        - regular file in the way, raise an exception\n        - parent directory(ies) does not exist, make them as well\n        From: http://code.activestate.com/recipes/82465-a-friendly-mkdir/\n    '
    if os.path.isdir(newdir):
        pass
    elif os.path.isfile(newdir):
        raise OSError("a file with the same name as the desired dir, '{0}', already exists.".format(newdir))
    else:
        (head, tail) = os.path.split(newdir)
        if (head and (not os.path.isdir(head))):
            mkdir_p(head)
        if tail:
            os.mkdir(newdir)