Skip to content

Commit f162bcc

Browse files
[3.14] gh-130536: Add details to os.path documentation (GH-130557) (#142800)
Co-authored-by: Arthur Wigo <[email protected]>
1 parent c727b99 commit f162bcc

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

Doc/library/os.path.rst

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ the :mod:`glob` module.)
5757
.. function:: abspath(path)
5858

5959
Return a normalized absolutized version of the pathname *path*. On most
60-
platforms, this is equivalent to calling the function :func:`normpath` as
61-
follows: ``normpath(join(os.getcwd(), path))``.
60+
platforms, this is equivalent to calling ``normpath(join(os.getcwd(), path))``.
61+
62+
.. seealso:: :func:`os.path.join` and :func:`os.path.normpath`.
6263

6364
.. versionchanged:: 3.6
6465
Accepts a :term:`path-like object`.
@@ -243,6 +244,8 @@ the :mod:`glob` module.)
243244
begins with a slash, on Windows that it begins with two (back)slashes, or a
244245
drive letter, colon, and (back)slash together.
245246

247+
.. seealso:: :func:`abspath`
248+
246249
.. versionchanged:: 3.6
247250
Accepts a :term:`path-like object`.
248251

@@ -357,14 +360,28 @@ the :mod:`glob` module.)
357360
concatenation of *path* and all members of *\*paths*, with exactly one
358361
directory separator following each non-empty part, except the last. That is,
359362
the result will only end in a separator if the last part is either empty or
360-
ends in a separator. If a segment is an absolute path (which on Windows
361-
requires both a drive and a root), then all previous segments are ignored and
362-
joining continues from the absolute path segment.
363+
ends in a separator.
364+
365+
If a segment is an absolute path (which on Windows requires both a drive and
366+
a root), then all previous segments are ignored and joining continues from the
367+
absolute path segment. On Linux, for example::
368+
369+
>>> os.path.join('/home/foo', 'bar')
370+
'/home/foo/bar'
371+
>>> os.path.join('/home/foo', '/home/bar')
372+
'/home/bar'
363373

364374
On Windows, the drive is not reset when a rooted path segment (e.g.,
365375
``r'\foo'``) is encountered. If a segment is on a different drive or is an
366-
absolute path, all previous segments are ignored and the drive is reset. Note
367-
that since there is a current directory for each drive,
376+
absolute path, all previous segments are ignored and the drive is reset. For
377+
example::
378+
379+
>>> os.path.join('c:\\', 'foo')
380+
'c:\\foo'
381+
>>> os.path.join('c:\\foo', 'd:\\bar')
382+
'd:\\bar'
383+
384+
Note that since there is a current directory for each drive,
368385
``os.path.join("c:", "foo")`` represents a path relative to the current
369386
directory on drive :file:`C:` (:file:`c:foo`), not :file:`c:\\foo`.
370387

@@ -518,8 +535,8 @@ the :mod:`glob` module.)
518535
*path* is empty, both *head* and *tail* are empty. Trailing slashes are
519536
stripped from *head* unless it is the root (one or more slashes only). In
520537
all cases, ``join(head, tail)`` returns a path to the same location as *path*
521-
(but the strings may differ). Also see the functions :func:`dirname` and
522-
:func:`basename`.
538+
(but the strings may differ). Also see the functions :func:`join`,
539+
:func:`dirname` and :func:`basename`.
523540

524541
.. versionchanged:: 3.6
525542
Accepts a :term:`path-like object`.

0 commit comments

Comments
 (0)