Organization of This Chapter
First of all, this chapter, in File Objects, discusses the most typical way in which Python programs read and write data, which is via built-in file
objects. Immediately after that, the chapter covers the polymorphic concept of file-like objects (objects that are not files but behave to some extent like files) in File-Like Objects and Polymorphism.
The chapter next covers modules that deal with temporary files and file-like objects (tempfile
in The tempfile Module, StringIO
and cStringIO
in The StringIO and cStringIO Modules).
Next comes the coverage of modules that help you access the contents of text and binary files (fileinput
in The fileinput Module, linecache
in The linecache Module, struct
in The struct Module) and support compressed files and other data archives (gzip
in The gzip Module, bz2
in The bz2 Module, tarfile
in The tarfile Module, zipfile
in The zipfile Module, zlib
in The zlib Module).
In Python, the os
module supplies many of the functions that operate on the filesystem, so this chapter continues by introducing the os
module in The os Module. The chapter then covers, in Filesystem Operations, operations on the filesystem (comparing, copying, and deleting directories and files, working with file paths, and accessing low-level file descriptors) offered by os
(in File and Directory Functions of the os Module), os.path
(in The os.path Module), and other modules (dircache
in “listdir”, stat
in The stat Module, filecmp
in The filecmp Module ...
Get Python in a Nutshell, 2nd Edition 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.