One of our principle forms of interaction with the OS is working with files. The pathlib module makes this particularly flexible. While the OS can represent a path to a file as a string, there is considerable syntactic subtlety to the strings that are used. Rather than try to parse the strings directly, it's much more pleasant to create Path objects. These can both compose and decompose paths from their constituent parts.
Path composition uses the / operator to assemble a Path from starting Path and str objects. This operator works for Windows as well as POSIX-compliant operating systems, such as Linux and macOS. Because a single operator will build appropriate paths, it's best to use Path objects for all filesystem access.
Here are some examples of building a Path object:
- Path.home() / "some_file.dat": This names a given file in the...