diff options
author | Barry Warsaw <barry@python.org> | 2014-08-05 15:28:12 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 2014-08-05 15:28:12 (GMT) |
commit | 7c549c4e6445b25c95491571af8dfa6532570866 (patch) | |
tree | d5f3bf11bea329a38e91ad4bddc66adef5aeae4f /Doc | |
parent | 17fd1e1013e27032a8a14cc4a1e0521ef75d3699 (diff) | |
download | cpython-7c549c4e6445b25c95491571af8dfa6532570866.zip cpython-7c549c4e6445b25c95491571af8dfa6532570866.tar.gz cpython-7c549c4e6445b25c95491571af8dfa6532570866.tar.bz2 |
- Issue #21539: Add a *exists_ok* argument to `Pathlib.mkdir()` to mimic
`mkdir -p` and `os.makedirs()` functionality. When true, ignore
FileExistsErrors. Patch by Berker Peksag.
(With minor cleanups, additional tests, doc tweaks, etc. by Barry)
Also:
* Remove some unused imports in test_pathlib.py reported by pyflakes.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/pathlib.rst | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst index 0a2a4e3..67ed914 100644 --- a/Doc/library/pathlib.rst +++ b/Doc/library/pathlib.rst @@ -791,7 +791,7 @@ call fails (for example because the path doesn't exist): the symbolic link's information rather than its target's. -.. method:: Path.mkdir(mode=0o777, parents=False) +.. method:: Path.mkdir(mode=0o777, parents=False, exist_ok=False) Create a new directory at this given path. If *mode* is given, it is combined with the process' ``umask`` value to determine the file mode @@ -805,6 +805,16 @@ call fails (for example because the path doesn't exist): If *parents* is false (the default), a missing parent raises :exc:`FileNotFoundError`. + If *exist_ok* is false (the default), an :exc:`FileExistsError` is + raised if the target directory already exists. + + If *exist_ok* is true, :exc:`FileExistsError` exceptions will be + ignored (same behavior as the POSIX ``mkdir -p`` command), but only if the + last path component is not an existing non-directory file. + + .. versionchanged:: 3.5 + The *exist_ok* parameter was added. + .. method:: Path.open(mode='r', buffering=-1, encoding=None, errors=None, newline=None) |