diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-01-05 23:04:57 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-05 23:04:57 (GMT) |
commit | 4bdc57a3d2aceadbc9150febe6717ef92b8d6aa5 (patch) | |
tree | 7759224b4ae1bf4d26bd92d5b8c59da4fc430a67 /Doc | |
parent | 825ad05e1f948d6f19c3564a392e027aaebf0d37 (diff) | |
download | cpython-4bdc57a3d2aceadbc9150febe6717ef92b8d6aa5.zip cpython-4bdc57a3d2aceadbc9150febe6717ef92b8d6aa5.tar.gz cpython-4bdc57a3d2aceadbc9150febe6717ef92b8d6aa5.tar.bz2 |
gh-87691: add an absolute path pathlib example in / operator docs (GH-100737)
The behaviour is fully explained a couple paragraphs above, but it may be useful to have a brief example to cover the behaviour.
(cherry picked from commit 1ae619c911ec8e096f83eeb7cc57fcd966950a3d)
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Automerge-Triggered-By: GH:hauntsaninja
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/pathlib.rst | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst index f969b11..316fee2 100644 --- a/Doc/library/pathlib.rst +++ b/Doc/library/pathlib.rst @@ -212,7 +212,10 @@ Paths of a different flavour compare unequal and cannot be ordered:: Operators ^^^^^^^^^ -The slash operator helps create child paths, similarly to :func:`os.path.join`:: +The slash operator helps create child paths, mimicking the behaviour of +:func:`os.path.join`. For instance, when several absolute paths are given, the +last is taken as an anchor; for a Windows path, changing the local root doesn't +discard the previous drive setting:: >>> p = PurePath('/etc') >>> p @@ -222,6 +225,10 @@ The slash operator helps create child paths, similarly to :func:`os.path.join`:: >>> q = PurePath('bin') >>> '/usr' / q PurePosixPath('/usr/bin') + >>> p / '/an_absolute_path' + PurePosixPath('/an_absolute_path') + >>> PureWindowsPath('c:/Windows', '/Program Files') + PureWindowsPath('c:/Program Files') A path object can be used anywhere an object implementing :class:`os.PathLike` is accepted:: |