1. The role of the Pickle module
persist objects such as dictionaries, lists, strings, and so on to disk for later use
2. Pickle Object Serialization
Pickle module The process of converting any Python object into a system byte is called a serialized object.
3. Pickle and Cpickle
The Python standard library provides pickle and cpickle modules. Cpickle is encoded in C and is higher in efficiency than pickle , but the type defined in the Cpickle module cannot be inherited (most of the time, we do not need to inherit from these types, we recommend using Cpickle). The serialization/deserialization rules for cpickle and Pickle are the same, using pickle to serialize an object that can be deserialized using Cpickle .
4. Functions commonly used in pickle (1)pickle.dump (obj, file, [, Protocol])
Role: Data to be persisted "object", saved to "file", using 3 kinds of protocols, index 0 is ascii,1 for the old binary, 2 is the new binary protocol, the difference is that 2 is more efficient (by default, 0 protocol)
(2)pickle.load (file)
Role: Reading strings from "files" and deserializing them into Python data objects
(3)Pickle.dumps (obj[, Protocol])
Function: Serializes an Obj object into a string rather than depositing it in a file
- Obj: obj object to serialize
- Protocal: If the item is omitted, the default is 0. If negative or Highest_protocol, the highest protocol version is used
(4)pickle.loads (String)
Function: The Obj object before serialization is read from a string
Python:pickle Module Learning