OS Path Module

BrandonDusch's avatar
Published Jun 25, 2022
Contribute to Docs

The os.path module supports operations on pathnames, which can be passed as strings or bytes. The functions under os.path differ from the ones under the glob module in that they are used for working with and creating specific paths (rather than just filtering through them under certain criteria).

OS Path Module

.basename()
Returns the part of a pathname after the last forward-slash.
.dirname()
Returns the part of the pathname ranging from the start to the last forward-slash.
.exists()
Checks whether a given file or folder exists in the directory of an operating system.
.join()
Returns a string of pathnames delimited with a forward-slash.

All contributors

Contribute to Docs

Learn Python on Codecademy