[issue9299] os.mkdir() and os.makedirs() add a keyword argument to suppress "File exists" exception.
Terry J. Reedy
report at bugs.python.org
Wed Jul 21 04:32:13 CEST 2010
Terry J. Reedy <tjreedy at udel.edu> added the comment:
Discussion has continued on pydev thread "mkdir -p in python". Some suggested a new function. Others questioned the details of the new behavior. Guido prefers the flag approach and imitation of mkdir -p.
"-1 on a new function (despite the constant-argument
guideline) and +1 on a flag. If it weren't for backwards compatibility
I'd just change os.makedirs() to act like mkdir -p period, but the
last opportunity we had for that was Python 3.0."
So, the patch should either leave behavior untouched or imitate -p behavior. That to me says that the parameter passed to mkdirs should be propagated to each mkdir call, as the 9299 patch does, and not set to a fixed value.
OS imports mkdir for one of posix, nt, os2, or ce modules. Since these do not have private '_xx' names and might be imported directly, I think the C-coded mkdir should have the parameter too, as the 9299 patch already does.
The patch changes posixmodule.c. Are all of posix, nt, os2, and ce created from the one file, or is does the patch need to change other C files?
The patch simply augments the very skimpy docstring with
"[, exist_ok=False]". Please add something after "Create a directory." like "If exist_ok is False, raise BlahError if the path already exists." Many doc strings are so terse as to be barely usable, but this is not a requirement. See help(compile) for one that is complete.
Python tracker <report at bugs.python.org>
More information about the Python-bugs-list