Python 3 offers the module pathlib, which provides the class Path. A path object encapsulates either a system file or directory and is transparent to the operating system.
A Path object overloads the division operator / and allows for the following path operations:
On POSIX systems, / with correctly concatenate the directory and filename with a slash. On Windows, the back slash is used instead. Almost all standard libraries support Path objects. For those calls not supporting it, the Path object can be converted back to a string e.g. using str(my_file_path).
Recommendation: Use pathlib to improve cross-platform support and ease working with paths.
Python 3 offers the module pathlib, which provides the class
Path
. A path object encapsulates either a system file or directory and is transparent to the operating system.A
Path
object overloads the division operator/
and allows for the following path operations:On POSIX systems,
/
with correctly concatenate the directory and filename with a slash. On Windows, the back slash is used instead. Almost all standard libraries support Path objects. For those calls not supporting it, the Path object can be converted back to a string e.g. usingstr(my_file_path)
.Recommendation: Use
pathlib
to improve cross-platform support and ease working with paths.