OS Path Module

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 diretory of an operating system.
.join()
Returns a string of pathnames delimited with a forward-slash.

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn Python on Codecademy