Skip to content

Commit ce6549f

Browse files
Improve os.path documentation
Added cross-references to related functions and provided an example for os.path.join to enhance clarity.
1 parent a594998 commit ce6549f

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

Doc/library/os.path.rst

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ the :mod:`glob` module.)
6060
platforms, this is equivalent to calling the function :func:`normpath` as
6161
follows: ``normpath(join(os.getcwd(), path))``.
6262

63+
.. seealso::
64+
:func:`os.path.join` - for combining paths in an OS-independent way.
65+
6366
.. versionchanged:: 3.6
6467
Accepts a :term:`path-like object`.
6568

@@ -239,7 +242,10 @@ the :mod:`glob` module.)
239242

240243
.. function:: isabs(path)
241244

242-
Return ``True`` if *path* is an absolute pathname. On Unix, that means it
245+
Return ``True`` if *path* is an absolute pathname.
246+
247+
.. seealso::
248+
:func:`os.path.abspath` - for converting paths to absolute paths. On Unix, that means it
243249
begins with a slash, on Windows that it begins with two (back)slashes, or a
244250
drive letter, colon, and (back)slash together.
245251

@@ -352,7 +358,13 @@ the :mod:`glob` module.)
352358

353359
.. function:: join(path, *paths)
354360

355-
Join one or more path segments intelligently. The return value is the
361+
Join one or more path segments intelligently.
362+
363+
Example::
364+
365+
>>> import os
366+
>>> os.path.join("/home/foo", "/home/bar")
367+
'/home/bar' The return value is the
356368
concatenation of *path* and all members of *\*paths*, with exactly one
357369
directory separator following each non-empty part, except the last. That is,
358370
the result will only end in a separator if the last part is either empty or
@@ -488,7 +500,10 @@ the :mod:`glob` module.)
488500
.. function:: split(path)
489501

490502
Split the pathname *path* into a pair, ``(head, tail)`` where *tail* is the
491-
last pathname component and *head* is everything leading up to that. The
503+
last pathname component and *head* is everything leading up to that.
504+
505+
.. seealso::
506+
:func:`os.path.join` - for joining paths efficiently. The
492507
*tail* part will never contain a slash; if *path* ends in a slash, *tail*
493508
will be empty. If there is no slash in *path*, *head* will be empty. If
494509
*path* is empty, both *head* and *tail* are empty. Trailing slashes are

0 commit comments

Comments
 (0)