Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitba587ed

Browse files
authored
gh-130536: Add details toos.path documentation (#130557)
1 parentc24e238 commitba587ed

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

@@ -527,8 +544,8 @@ the :mod:`glob` module.)
527544
*path* is empty, both *head* and *tail* are empty. Trailing slashes are
528545
stripped from *head* unless it is the root (one or more slashes only). In
529546
all cases, ``join(head, tail)`` returns a path to the same location as *path*
530-
(but the strings may differ). Also see the functions:func:`dirname` and
531-
:func:`basename`.
547+
(but the strings may differ). Also see the functions:func:`join`,
548+
:func:`dirname` and:func:`basename`.
532549

533550
..versionchanged::3.6
534551
Accepts a:term:`path-like object`.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp