Skip to content

Commit

Permalink
bpo-35183: Add typical examples to os.path.splitext docs (GH-27286) (G…
Browse files Browse the repository at this point in the history
…H-27563)

(cherry picked from commit aa0894b)

Co-authored-by: Jake Stockwin <[email protected]>
  • Loading branch information
miss-islington and jstockwin authored Aug 2, 2021
1 parent aa72668 commit 14cb669
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
33 changes: 26 additions & 7 deletions Doc/library/os.path.rst
Original file line number Diff line number Diff line change
Expand Up @@ -470,12 +470,16 @@ the :mod:`glob` module.)
On Windows, splits a pathname into drive/UNC sharepoint and relative path.

If the path contains a drive letter, drive will contain everything
up to and including the colon.
e.g. ``splitdrive("c:/dir")`` returns ``("c:", "/dir")``
up to and including the colon::

>>> splitdrive("c:/dir")
("c:", "/dir")

If the path contains a UNC path, drive will contain the host name
and share, up to but not including the fourth separator.
e.g. ``splitdrive("//host/computer/dir")`` returns ``("//host/computer", "/dir")``
and share, up to but not including the fourth separator::

>>> splitdrive("//host/computer/dir")
("//host/computer", "/dir")

.. versionchanged:: 3.6
Accepts a :term:`path-like object`.
Expand All @@ -484,9 +488,24 @@ the :mod:`glob` module.)
.. function:: splitext(path)

Split the pathname *path* into a pair ``(root, ext)`` such that ``root + ext ==
path``, and *ext* is empty or begins with a period and contains at most one
period. Leading periods on the basename are ignored; ``splitext('.cshrc')``
returns ``('.cshrc', '')``.
path``, and the extension, *ext*, is empty or begins with a period and contains at
most one period.

If the path contains no extension, *ext* will be ``''``::

>>> splitext('bar')
('bar', '')

If the path contains an extension, then *ext* will be set to this extension,
including the leading period. Note that previous periods will be ignored::

>>> splitext('foo.bar.exe')
('foo.bar', '.exe')

Leading periods on the basename are ignored::

>>> splitext('.cshrc')
('.cshrc', '')

.. versionchanged:: 3.6
Accepts a :term:`path-like object`.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add typical examples to os.path.splitext docs

0 comments on commit 14cb669

Please sign in to comment.