Serialization
Python supplies a number of modules dealing with I/O operations that serialize (save) entire Python objects to various kinds of byte streams and deserialize (load and recreate) Python objects back from such streams. Serialization is also known as marshaling.
The marshal Module
The marshal
module supports the specific serialization tasks needed to save and reload compiled Python files (.pyc and .pyo). marshal
handles only fundamental built-in data types: None
, numbers (int
, long
, float
, complex
), strings (plain and Unicode), code objects, and built-in containers (tuple
, list
, dict
) whose items are instances of elementary types. marshal
does not handle sets nor user-defined types and classes. marshal
is faster than other serialization modules, and is the one such module that supports code objects. Module marshal
supplies the following functions.
dump, dumps |
|
load, loads |
|
Get Python in a Nutshell, 2nd 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.