mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
gh-87691: clarify use of anchor in pathlib docs (#100782)
This is feedback from https://github.com/python/cpython/pull/100737#discussion_r1062968696 This matches the wording from the `os.path.join` docs better: https://docs.python.org/3/library/os.path.html#os.path.join In particular, the previous use of "anchor" was incorrect given the pathlib definition of "anchor". Co-authored-by: Barney Gale <barney.gale@gmail.com>
This commit is contained in:
parent
0a7936a38f
commit
2f2fa03ff3
1 changed files with 8 additions and 8 deletions
|
@ -118,16 +118,16 @@ we also call *flavours*:
|
||||||
>>> PurePath()
|
>>> PurePath()
|
||||||
PurePosixPath('.')
|
PurePosixPath('.')
|
||||||
|
|
||||||
When several absolute paths are given, the last is taken as an anchor
|
If a segment is an absolute path, all previous segments are ignored
|
||||||
(mimicking :func:`os.path.join`'s behaviour)::
|
(like :func:`os.path.join`)::
|
||||||
|
|
||||||
>>> PurePath('/etc', '/usr', 'lib64')
|
>>> PurePath('/etc', '/usr', 'lib64')
|
||||||
PurePosixPath('/usr/lib64')
|
PurePosixPath('/usr/lib64')
|
||||||
>>> PureWindowsPath('c:/Windows', 'd:bar')
|
>>> PureWindowsPath('c:/Windows', 'd:bar')
|
||||||
PureWindowsPath('d:bar')
|
PureWindowsPath('d:bar')
|
||||||
|
|
||||||
However, in a Windows path, changing the local root doesn't discard the
|
On Windows, the drive is not reset when a rooted relative path
|
||||||
previous drive setting::
|
segment (e.g., ``r'\foo'``) is encountered::
|
||||||
|
|
||||||
>>> PureWindowsPath('c:/Windows', '/Program Files')
|
>>> PureWindowsPath('c:/Windows', '/Program Files')
|
||||||
PureWindowsPath('c:/Program Files')
|
PureWindowsPath('c:/Program Files')
|
||||||
|
@ -212,10 +212,10 @@ Paths of a different flavour compare unequal and cannot be ordered::
|
||||||
Operators
|
Operators
|
||||||
^^^^^^^^^
|
^^^^^^^^^
|
||||||
|
|
||||||
The slash operator helps create child paths, mimicking the behaviour of
|
The slash operator helps create child paths, like :func:`os.path.join`.
|
||||||
:func:`os.path.join`. For instance, when several absolute paths are given, the
|
If the argument is an absolute path, the previous path is ignored.
|
||||||
last is taken as an anchor; for a Windows path, changing the local root doesn't
|
On Windows, the drive is not reset when the argument is a rooted
|
||||||
discard the previous drive setting::
|
relative path (e.g., ``r'\foo'``)::
|
||||||
|
|
||||||
>>> p = PurePath('/etc')
|
>>> p = PurePath('/etc')
|
||||||
>>> p
|
>>> p
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue