Pickle module implements binary protocols for serializing and de-serializing a python object structure.
for example list, dictionary, method and class object can be serialized, or they can be restored.
Pickling is the process whereby a Python object hierarchy ic converted into a byte stream.
Unpickling is the inverse operation, whereby a byte stream(from a binary file) is converted back into an object hierarchy.
Pickling and unpickling also known as "serialization" and "deserialization"
To serialize an object, we can call pickle.dump() method, similarly to de-serialize a data stream , we have to call pickle.load() method.
The pickle module keeps track of the objects it has already serialized, so that later references to the same object won't be serialized again.
What can be pickle and unpickled?
The following types can be pickled.
None, True, and False
int, float, and complex types
strings, bytes, and byte arrays
tuples, lists, and dictionaries
functions defined at the top level of module.
built-in functions defined at the top level of module.
classes that are defined at the top level of module.
Lambdas cannot pickled.
serializing and deserializing a dictionary object
serializing and deserializing a class object:
pickling and unpickling a list object:
pickling and unpickling a function: