Serializing and Saving - JSON, YAML, Pickle, CSV, and XML

To make a Python object persistent, we must convert it into bytes and write the bytes to a file. We'll call this transformation serialization; it is also called marshaling, deflating, or encoding. We'll look at several ways to serialize a Python object to a stream of bytes. It's important to note that we're focused on representing the state of an object, separate from the full definition of the class and its methods and superclasses.

A serialization scheme includes a physical data format. Each format offers some advantages and disadvantages. There's no best format to represent the state of objects. helps to distinguish the format from the logical data layout, which may be a simple ...

Get Mastering Object-Oriented Python - Second Edition 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.