Skip to content

Latest commit

 

History

History
62 lines (48 loc) · 3.28 KB

os_path_doc.md

File metadata and controls

62 lines (48 loc) · 3.28 KB

#os.path — Common pathname manipulations ####Link to full documentation: (https://docs.python.org/3/library/os.path.html)

#####Source code: Lib/posixpath.py (for POSIX), Lib/ntpath.py (for Windows NT), and Lib/macpath.py (for Macintosh) ###Description

This module implements functions on pathnames. To read or write files see open(), and for accessing the filesystem see the os module. Path parameters can be passed as either strings, or bytes. Applications are encouraged to represent file names as (Unicode) character strings. Unfortunately, some file names may not be representable as strings on Unix, so applications that need to support arbitrary file names on Unix should use bytes objects to represent path names. Vice versa, using bytes objects cannot represent all file names on Windows (in the standard mbcs encoding), hence Windows applications should use string objects to access all files.

Unlike a unix shell, Python does not do any automatic path expansions. Functions such as expanduser() and expandvars() can be invoked explicitly when an application desires shell-like path expansion. (See also the glob module.)

See also The pathlib module (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.path module 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: #####posixpath for UNIX-style paths

#####ntpath for Windows paths

#####macpath for old-style MacOS paths ##Methods (used in Categories.py)

os.path.abspath(path)

###Description

Return a normalized absolutized version of the pathname path. On most platforms, this is equivalent to calling the function normpath() as follows:

normpath(join(os.getcwd(), path))

###Parameters

path: type = str

os.path.join(path, *paths)

###Description

Join one or more path components intelligently. ###Parameters

paths: type = str

*paths: type = str ###Return

Concatenation of path and any members of *paths with exactly one directory separator (os.sep) following each non-empty part except the last, meaning that the result will only end in a separator if the last part is empty. If a component is an absolute path, all previous components are thrown away and joining continues from the absolute path component.

###Note:

On Windows, the drive letter is not reset when an absolute path component (e.g., r'\foo') is encountered. If a component contains a drive letter, all previous components are thrown away and the drive letter is reset. Note that since there is a current directory for each drive, os.path.join("c:", "foo") represents a path relative to the current directory on drive C: (c:foo), not c:\foo.

Changed in version 3.6: Accepts a path-like object for path and paths. Changed in version 3.6: Accepts a path-like object.