Chapter 10. Files and Strings

Let's take a step back from the higher-level patterns now, and cover several Python constructs we've used in all our examples, but without any details. We'll be looking at files, IO, and serializing and loading data. Along the way, we'll find out how complicated Python's excessively simple strings really are. In particular, we'll see:

  • The complexities of strings, bytes, and byte array
  • The ins and outs of string formatting
  • How to open files
  • Context managers
  • A few ways to serialize data

Strings

Strings are a basic primitive in Python; we've used them in nearly every example we've discussed so far. All they do is represent an immutable sequence of characters. Of course, "character" is a bit of an ambiguous word; can Python ...

Get Python 3 Object Oriented Programming 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.