As the OS filesystem (and network) works in bytes, we need to represent the values of an object's instance variables as a serialized stream of bytes. Often, we'll use a two-step transformation to get the bytes: firstly, we'll represent the state of an object as a string; secondly, we'll rely on the Python str class to provide bytes in a standard encoding. Python's built-in features for encoding a string into bytes neatly solves the second part of the problem. This allows most serialization methods to focus on creating strings.
When we look at our OS filesystems, we see two broad classes of devices: block-mode devices and character-mode devices. Block-mode devices can also be called seekable because the OS supports a seek operation that can access any byte in the file in an arbitrary order. Character-mode devices are...