Serialization is a process of converting Python object or data
structures hierarchy into byte streams so that it can be written
into a file.
A byte stream is, a stream of bytes – one byte is composed of
8 bits of zeros and ones.
These byte streams can then be stored or transferred easily.
Video games might be the most intuitive example of
serialization's usefulness.
Serialization is the process of converting object state into a
format that can be transmitted or stored. The serialization
changes the object state into series of bits.
Is the inverse of Pickling where a byte stream is converted into
an object hierarchy.
Unpickling produces the exact replica of the original object.
The object state could be reconstructed later in the opposite
process, called deserialization.
Python’s module to achieve serialization/de-serialization.
In order to work with the pickle module, you must first import
it in your program.
import pickle
Then you may use dump() and load() methods to write and
read from an open binary file respectively.
Import pickle module.
Open binary file in the required mode.
Process binary file by writing/reading objects using
appropriate methods.
Once done, close the file
A binary file is opened in the same way as any other file, but
make sure to use “b” with file modes to open a file in binary
mode.
file=open(“[Link]”,”wb”)
OR Notice ‘b’ is used with the file modes
file=open(“[Link]”,”rb”)
[Link]()
In order to write an object on to a binary file, use dump()
function of pickle module.
[Link](<object-to-be-written>,<file handle-of-open-file>)
In order to write an object on to a binary file, use load()
function of pickle module.
<object>=[Link](<file handle-of-open-file>)