Skip to content

Commit 55d3e8a

Browse files
gh-84548: Document Windows specific behavior of abspath() and realpath()
On Windows abspath() resolves a drive-relative path against the current directory of the specified drive, capitalizes the drive letter and strips trailing dots and spaces, so the result can differ from normpath(join(os.getcwd(), path)). realpath() returns the path in the case reported by the operating system.
1 parent 998b890 commit 55d3e8a

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

Doc/library/os.path.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ the :mod:`glob` module.)
5959
Return a normalized absolutized version of the pathname *path*. On most
6060
platforms, this is equivalent to calling ``normpath(join(os.getcwd(), path))``.
6161

62+
On Windows the path is normalized by the operating system,
63+
therefore the result can differ from ``normpath(join(os.getcwd(), path))``.
64+
A drive-relative path is resolved against the current directory
65+
of the specified drive, and the drive letter is capitalized.
66+
Trailing dots and spaces are stripped.
67+
For example::
68+
69+
>>> os.path.abspath('c:spam')
70+
'C:\\Temp\\spam'
71+
>>> os.path.abspath('c:/temp/spam. . .')
72+
'c:\\temp\\spam'
73+
6274
.. seealso:: :func:`os.path.join` and :func:`os.path.normpath`.
6375

6476
.. versionchanged:: 3.6
@@ -435,6 +447,9 @@ the :mod:`glob` module.)
435447
links encountered in the path (if they are supported by the operating
436448
system). On Windows, this function will also resolve MS-DOS (also called 8.3)
437449
style names such as ``C:\\PROGRA~1`` to ``C:\\Program Files``.
450+
The returned path uses the case reported by the operating system,
451+
which can differ from the case of *path*,
452+
in particular the drive letter is capitalized.
438453

439454
By default, the path is evaluated up to the first component that does not
440455
exist, is a symlink loop, or whose evaluation raises :exc:`OSError`.

0 commit comments

Comments
 (0)