Skip to content

Commit 4bdc57a

Browse files
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 1ae619c) Co-authored-by: Shantanu <[email protected]> Automerge-Triggered-By: GH:hauntsaninja
1 parent 825ad05 commit 4bdc57a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Doc/library/pathlib.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,10 @@ Paths of a different flavour compare unequal and cannot be ordered::
212212
Operators
213213
^^^^^^^^^
214214

215-
The slash operator helps create child paths, similarly to :func:`os.path.join`::
215+
The slash operator helps create child paths, mimicking the behaviour of
216+
:func:`os.path.join`. For instance, when several absolute paths are given, the
217+
last is taken as an anchor; for a Windows path, changing the local root doesn't
218+
discard the previous drive setting::
216219

217220
>>> p = PurePath('/etc')
218221
>>> p
@@ -222,6 +225,10 @@ The slash operator helps create child paths, similarly to :func:`os.path.join`::
222225
>>> q = PurePath('bin')
223226
>>> '/usr' / q
224227
PurePosixPath('/usr/bin')
228+
>>> p / '/an_absolute_path'
229+
PurePosixPath('/an_absolute_path')
230+
>>> PureWindowsPath('c:/Windows', '/Program Files')
231+
PureWindowsPath('c:/Program Files')
225232

226233
A path object can be used anywhere an object implementing :class:`os.PathLike`
227234
is accepted::

0 commit comments

Comments
 (0)