summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-08-02 18:10:47 (GMT)
committerGitHub <noreply@github.com>2021-08-02 18:10:47 (GMT)
commit14cb669357bc30bdc235d1c32ee1b99be05ac9d8 (patch)
tree3019388d3ee581151daa6396d10d154b992320bf /Doc
parentaa7266854abc63524b4be40a3a83977b8ad166c6 (diff)
downloadcpython-14cb669357bc30bdc235d1c32ee1b99be05ac9d8.zip
cpython-14cb669357bc30bdc235d1c32ee1b99be05ac9d8.tar.gz
cpython-14cb669357bc30bdc235d1c32ee1b99be05ac9d8.tar.bz2
bpo-35183: Add typical examples to os.path.splitext docs (GH-27286) (GH-27563)
(cherry picked from commit aa0894b3792901adb91e5f6d049154b7bcb980ec) Co-authored-by: Jake Stockwin <jake.stockwin@optimorlabs.com>
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/os.path.rst33
1 files changed, 26 insertions, 7 deletions
diff --git a/Doc/library/os.path.rst b/Doc/library/os.path.rst
index e2f4342..a66b3c5 100644
--- a/Doc/library/os.path.rst
+++ b/Doc/library/os.path.rst
@@ -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`.
@@ -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`.