Chapter 6. The File System
Python’s standard library includes a large range of tools for working with files on the file system, building and parsing filenames, and examining file contents.
The first step in working with files is to determine the name of the file to work on. Python represents filenames as simple strings, but provides tools for building them from standard, platform-independent components in
os.path (page 296).
pathlib (page 305) module provides an object-oriented API for working with file system paths. Using it instead of
os.path offers greater convenience because it operates at a higher level of abstraction.
List the contents of a directory with
os (page 1227), or use
glob (page 319) to build a list of filenames ...