Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-35183: Add typical examples to os.path.splitext docs #27286

Merged
merged 6 commits into from
Aug 2, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
bpo-35183: Change os.path doc examples to be repr
  • Loading branch information
jstockwin committed Jul 23, 2021
commit 06c0caefec3503010f9adbbac001950a82e72eb2
30 changes: 20 additions & 10 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 @@ -487,15 +491,21 @@ the :mod:`glob` module.)
path``, and *ext* is empty or begins with a period and contains at most one
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nitpicky (sorry). Note that up here in the prior docs, "ext" is italicized, then you switch to monospace. In general, throughout python documentation, you'll see italics used when referencing arguments or variable names in the midst of prose. I suggest changing "ext" on lines 490 and 493 to italics to match the style from the first paragraph.

period.

If the path contains no extension, *ext* will be ``''``.
e.g. ``splitext('bar')`` returns ``('bar', '')``
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.
e.g. ``splitext('foo.bar.exe')`` returns ``('foo.bar', '.exe')``.
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::

Leading periods on the basename are ignored.
e.g. ``splitext('.cshrc')`` returns ``('.cshrc', '')``.
>>> splitext('.cshrc')
('.cshrc', '')

.. versionchanged:: 3.6
Accepts a :term:`path-like object`.
Expand Down