Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aa0894b

Browse files
authored
bpo-35183: Add typical examples to os.path.splitext docs (GH-27286)
1 parent d382bde commit aa0894b

2 files changed

Lines changed: 27 additions & 7 deletions

File tree

Doc/library/os.path.rst

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -470,12 +470,16 @@ the :mod:`glob` module.)
470470
On Windows, splits a pathname into drive/UNC sharepoint and relative path.
471471

472472
If the path contains a drive letter, drive will contain everything
473-
up to and including the colon.
474-
e.g. ``splitdrive("c:/dir")`` returns ``("c:", "/dir")``
473+
up to and including the colon::
474+
475+
>>> splitdrive("c:/dir")
476+
("c:", "/dir")
475477

476478
If the path contains a UNC path, drive will contain the host name
477-
and share, up to but not including the fourth separator.
478-
e.g. ``splitdrive("//host/computer/dir")`` returns ``("//host/computer", "/dir")``
479+
and share, up to but not including the fourth separator::
480+
481+
>>> splitdrive("//host/computer/dir")
482+
("//host/computer", "/dir")
479483

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

486490
Split the pathname *path* into a pair ``(root, ext)`` such that ``root + ext ==
487-
path``, and *ext* is empty or begins with a period and contains at most one
488-
period. Leading periods on the basename are ignored; ``splitext('.cshrc')``
489-
returns ``('.cshrc', '')``.
491+
path``, and the extension, *ext*, is empty or begins with a period and contains at
492+
most one period.
493+
494+
If the path contains no extension, *ext* will be ``''``::
495+
496+
>>> splitext('bar')
497+
('bar', '')
498+
499+
If the path contains an extension, then *ext* will be set to this extension,
500+
including the leading period. Note that previous periods will be ignored::
501+
502+
>>> splitext('foo.bar.exe')
503+
('foo.bar', '.exe')
504+
505+
Leading periods on the basename are ignored::
506+
507+
>>> splitext('.cshrc')
508+
('.cshrc', '')
490509

491510
.. versionchanged:: 3.6
492511
Accepts a :term:`path-like object`.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add typical examples to os.path.splitext docs

0 commit comments

Comments
 (0)