O'Reilly logo

The Python Standard Library by Example by Doug Hellmann

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required