Python 3 Feature Request: `pathlib` Use Trailing Slash Flag
Adam Hendry
adam.grant.hendry at gmail.com
Sun Aug 9 15:00:02 EDT 2020
`pathlib` trims trailing slashes by default, but certain packages require trailing slashes. In particular, `cx_Freeze.bdist_msi` option "directories" is used to build the package directory structure of a program and requires trailing slashes.
Does anyone think it would be a good idea to add a flag or argument to `pathlib.Path` to keep trailing slashes? For instance, I envision something like:
```
from pathlib import Path
my_path = Path(r"foo/bar/", keep_trailing_slash=True)
```
The argument could be made `False` by default to maintain backwards compatibility. The only way I know to keep the backslash and maintain cross-compatibility is as follows:
```
import os
from pathlib import Path
my_path = f"{Path(r"foo/bar").resolve()}{os.sep}"
```
although this returns a string and the `Path` object is lost.
Any thoughts?
More information about the Python-list
mailing list