Skip to content

Commit

Permalink
gh-87691: add an absolute path pathlib example in / operator docs (GH…
Browse files Browse the repository at this point in the history
…-100737)

The behaviour is fully explained a couple paragraphs above, but it may be useful to have a brief example to cover the behaviour.

Automerge-Triggered-By: GH:hauntsaninja
  • Loading branch information
hauntsaninja committed Jan 5, 2023
1 parent d84b1a9 commit 1ae619c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Doc/library/pathlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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::
Expand Down

0 comments on commit 1ae619c

Please sign in to comment.