Solutions
The correct answer is option 1.
Concept:
The pickle module implements binary protocols for serializing and de-serializing Python object structures.
Pickling:
- Serialization is also known as Pickling.
- Pickling is the process of converting a Python object hierarchy into a byte stream.
- Serialization is the process of converting an object in memory to a byte stream that can be stored on a disk or sent over a network.
- The pickling process is also called marshaling.
Example:
The following example serializes data into a binary file.
#!/usr/bin/python
import pickle
data = {
'a': [1, 4.0, 3, 4+6j],
'b': ("a red fox", b"and old falcon"),
'c': {None, True, False}
}
with open('data.bin', 'wb') as f:
pickle.dump(data, f, pickle.HIGHEST_PROTOCOL)
Unpickling:
- Deserialization is also known as unpickling.
- Unpickling is the process of converting a byte stream into an object hierarchy, which is the inverse of Pickling.
- Deserialization is the process of converting a byte stream to a Python object.
- The unpickling process is also called unmarshalling.
Example:
In the next example, we unpickle data from a binary file.
#!/usr/bin/python
import pickle
with open('data.bin', 'rb') as f:
data = pickle.load(f)
print(data)
Hence the correct answer is pickling.