8. Text and Binary Files

The earliest personal computers used old-fashioned, slow-winding cassette drives—the equivalent of a horse and buggy. But the world has changed.

What hasn’t changed is the importance of files and devices, which are all about persistent storage. Python provides many ways to read and write files. Python Without Fear presented basic techniques for text I/O. This chapter builds on those techniques as well as exploring ways of reading and writing raw, or binary, data.

Prepare to enter the exciting world of persistent data! But first, a review of the basics: What’s the difference between text and binary modes, as they apply to Python specifically?

8.1 Two Kinds of Files: Text and Binary

Python makes a major distinction between ...

Get Supercharged Python: Take Your Code to the Next Level, First 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.