Since Python 3.4, pathlib
has been available in the standard library. With pathlib
, file paths can be represented by proper Path
objects instead of plain strings as before. These objects make code dealing with file paths:
- Easier to read, especially because
/
is used to join paths together - More powerful, with most necessary methods and properties available directly on the object
- More consistent across operating systems, as peculiarities of the different systems are hidden by the
Path
object
In this video course, you’ve seen how to create Path
objects, read and write files, manipulate paths and the underlying file system, as well as some examples of how to iterate over many file paths.
To learn more about pathlib
, check out:
east4ming on Dec. 28, 2022
Need sample codes in this lesson. Thanks!