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).
The 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 listdir() from os (page 1227), or use glob (page 319) to build a list of filenames ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access