Often encountered in the Python program run to get some strings, lists, dictionaries and other data, want to save for a long time, easy to use later, rather than simply put in memory shutdown power loss data. The pickle module in the Python module is useful for converting objects into a format that can be transferred or stored.
First, Pickle object serialization
Pickle module The process of converting any Python object into a system byte is called a serialized object.
Ii. comparison of Pickle and cpickle
The former is completely in Python to implement the module, the Cpickle is implemented with C, it is faster than pickle many times faster, generally recommended if the computer as long as there is cpickle should use it.
Third, the dump () method of the Pickle module
There are 2 common function methods in the Pickle module, one called Dump () and the other called load ().
The third part, play Snake net first to explain to you Pickle.dump () method:
The syntax for this method is: Pickle.dump (object, file, [Usage Protocol])
Hint: The data to be persisted "object", Save to "file", use 3 kinds, index 0 is ascii,1 is old-fashioned 2, 2 is the new 2 binary protocol, the difference is in the latter more efficient.
By default, the dump method uses 0 to do the protocol.
Iv. Load method of the Pickle module
The load () method acts just as opposed to the dump () method above, which is serialized data, which is deserialized.
Syntax: pickle.load (file)
Tip: From the file, read the strings, deserialize them into Python's data objects, and manipulate them as you would normally manipulate the data types.