A byte stream is an ordered sequence of bytes used to represent serialized data or other binary content. In Python, pickling converts an object hierarchy into a byte stream that can be stored in a binary file or moved elsewhere; unpickling reverses the process. section 13.8
When used for serialized Python data, a byte stream supports these operations and limits:
- Store numbers, strings, collections, class instances, shared objects, and cyclic references. section 13.8
- Write and read multiple serialized values in sequence with pickle.dump and pickle.load. section 13.8
- Exclude code objects and system resources such as files or sockets from pickling. section 13.8
Persisting program state
Open a file in binary-write mode, dump values into the resulting byte stream, then reopen it in binary-read mode and load the values in the same order. The restored values are a=42, b=3.14, and c='test'.


