Why serialize?
How can the dictionary, list, collection and various objects in memory be saved in a file?
How to save instances of self defined classes in a file?
How to read data from files and let them restore to their own instances of corresponding classes in memory?
A set of protocols should be designed to save the data in memory to a file according to certain rules. File is a byte sequence, so data must be converted into byte sequence and output to file, which is called serialization. Conversely, the type restored from the byte sequence of a file to memory is deserialization.
definition
Serialization
Store objects in memory and turn them into bytes. -> Binary
Deserialization
将文件中的一个个字节恢复成内存中对象。<-二进制
Serializing and saving to a file is persistence.
The data can be serialized and persisted, or transmitted over the network; You can also deserialize the byte sequence received in the file or on the network.
Python provides a pickle library.
Pickle Library
Serialization and deserialization modules in Python
Serialized application
Generally speaking, local serialization is rarely used, and most application scenarios are in network transmission.
After the data is serialized, it is transmitted to the remote node through the network. The service on the remote server can deserialize the received data.
However, it should be noted that the remote receiver must have the corresponding data type when reversing the sequence, or an error will be reported. In particular, user-defined classes must have consistent definitions remotely.