Skip to content

Commit f7d4ed1

Browse files
[3.14] Docs: Add a diagram of pathlib path components (GH-159727) (#159874)
Co-authored-by: Paul Ganssle <1377457+pganssle@users.noreply.github.com>
1 parent fd93654 commit f7d4ed1

2 files changed

Lines changed: 82 additions & 0 deletions

File tree

‎Doc/library/pathlib-parts.svg‎

Lines changed: 67 additions & 0 deletions
Loading

‎Doc/library/pathlib.rst‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,21 @@ Methods and properties
307307

308308
from pathlib import PurePath, PurePosixPath, PureWindowsPath
309309

310+
The :attr:`~PurePath.parent`, :attr:`~PurePath.name`,
311+
:attr:`~PurePath.stem`, and :attr:`~PurePath.suffix` properties describe
312+
different parts of a path. For example, given::
313+
314+
>>> p = PurePosixPath('/srv/holy/grail.tar.gz')
315+
316+
.. image:: pathlib-parts.svg
317+
:align: center
318+
:class: invert-in-dark-mode
319+
:alt: For p = PurePosixPath('/srv/holy/grail.tar.gz'), p.parent is
320+
PurePosixPath('/srv/holy'), p.name is 'grail.tar.gz',
321+
p.stem is 'grail.tar', and p.suffix is '.gz'.
322+
323+
The stem excludes only the final suffix: in this example, it includes ``.tar``.
324+
310325
Pure paths provide the following methods and properties:
311326

312327
.. attribute:: PurePath.parser

0 commit comments

Comments
 (0)