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 on which to work. Python represents filenames as simple strings, but provides tools for building them from standard, platform-independent components in os.path
. List the contents of a directory with listdir()
from os
, or use glob
to build a list of filenames from a pattern.
The filename pattern matching used by glob
is also exposed directly through fnmatch
, so it can be used in other contexts.
dircache
provides an efficient way to scan and process the contents of a directory on the file ...
Get The Python Standard Library by Example now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.