os.path.join
Join path parts with the separator of the current operating system.
Python 3.13
os.path.join(path, *paths)- path
- The first part of the path.str | PathLike
- *paths
- The following parts of the path.str | PathLike
Return value
A string with the path; the existence of files is not checked.
Examples
Building a path from parts
Python 3.13
import os
print(os.path.join('/home/user', 'documents', 'file.txt'))/home/user/documents/file.txt
An absolute part discards the previous ones
Python 3.13
import os
print(os.path.join('/home/user', '/tmp', 'file.txt'))/tmp/file.txt
Details
If one of the parts is an absolute path, all parts before it are discarded.
