Message218832
As of Python 3.2, `os.makedirs()` takes `exist_ok` as a keyword argument. If set to true, the function does not raise an error if the directory already exists. This makes the function's behavior similar to `mkdir -p` on the UNIX commandline. (See https://docs.python.org/3/library/os.html#os.makedirs)
However, this functionality is missing in Python's new pathlib. In fact, the documentation for `Path.mkdir()` even mentions that if `parent=True` is passed, then it should behave like `mkdir -p`. This is accurate in that it indeed recursively makes any parent directories necessary, but it is inaccurate in that it raises an error if the directory already exists.
I propose that either `parents=True` should imply that there is no error if the directory already exists (which would be a backwards-incompatible change); or, there could be a new `exist_ok=True`, which could suppress the error for an existing directory. Either way, it ought to be possible to get the `mkdir -p` functionality easily from pathlib. And the documentation for `Path.mkdir()` should be updated to explain how to get this `mkdir -p` functionality, with the existing (inaccurate) `mkdir -p` mention removed. |
|
Date |
User |
Action |
Args |
2014-05-20 03:53:56 | garrison | set | recipients:
+ garrison |
2014-05-20 03:53:56 | garrison | set | messageid: <1400558036.91.0.766972225791.issue21539@psf.upfronthosting.co.za> |
2014-05-20 03:53:56 | garrison | link | issue21539 messages |
2014-05-20 03:53:55 | garrison | create | |
|