11 Text IO and Context Managers

I find that a project doesn’t feel real until I start working with files. Text-based files, the most common way to store data, are the key to retaining state between program runs.

While it’s perfectly simple to open a text file in Python, there are many silent subtleties that are often overlooked until they bite you in the rear. Many developers make do with some idiosyncratic combination of techniques that appear to work but are far removed from the beauty and simplicity of idiomatic Python.

In this chapter, I’ll break down the two central components involved in working with text files: streams and path-like ...

Get Dead Simple Python 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.