Primary
os.path ⚬|Documentation|1st|20251021141349-00-⌔
os.path — Common pathname manipulations — Python 3 documentation
os.path— Common pathname manipulationsSource code: Lib/genericpath.py, Lib/posixpath.py (for POSIX) and Lib/ntpath.py (for Windows).
This module implements some useful functions on pathnames. To read or write files see
open(), and for accessing the filesystem see theosmodule. The path parameters can be passed as strings, or bytes, or any object implementing theos.PathLikeprotocol.Unlike a Unix shell, Python does not do any automatic path expansions. Functions such as
expanduser()andexpandvars()can be invoked explicitly when an application desires shell-like path expansion. (See also theglobmodule.)See also: The
pathlibmodule offers high-level path objects.Note: All of these functions accept either only bytes or only string objects as their parameters. The result is an object of the same type, if a path or file name is returned.
Note: Since different operating systems have different path name conventions, there are several versions of this module in the standard library. The
os.pathmodule is always the path module suitable for the operating system Python is running on, and therefore usable for local paths. However, you can also import and use the individual modules if you want to manipulate a path that is always in one of the different formats. They all have the same interface:
posixpathfor UNIX-style pathsntpathfor Windows pathsChanged in version 3.8:
exists(),lexists(),isdir(),isfile(),islink(), andismount()now returnFalseinstead of raising an exception for paths that contain characters or bytes unrepresentable at the OS level.Printed 2026-06-28.
(echo:: @ ᯤ)
Link to original
Secondary
• • •