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
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 ...