Chapter 10. Files, Databases, Networks, and Contexts

Files and the filesystem are central to the way modern OSs work. Many OS resources are visible as part of the filesystem. For example, the Linux /dev/mem is a view into the processor's memory, implemented as a device visible in the filesystem. Python provides file objects that map to these OS features.

At a fundamental level, OS files are simply collections of bytes. In practice, we often work with files that are collections of Unicode characters. Python offers both views of files. With some file formats, we need to process the bytes. With text files, we expect Python to properly decode Unicode characters from the bytes.

A Python file object will generally be entangled with an OS resource. In ...

Get Python Essentials 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.