in Technology by
What is pickling and unpickling in Python?

1 Answer

0 votes
by

Python library offers a feature - serialization out of the box. Serializing a object refers to transforming it into a format that can be stored, so as to be able to deserialize it later on, to obtain the original object. Here, the pickle module comes into play.

Pickling
Pickling is the name of the serialization process in Python. Any object in Python can be serialized into a byte stream and dumped as a file in the memory. The process of pickling is compact but pickle objects can be compressed further. Moreover, pickle keeps track of the objects it has serialized and the serialization is portable across versions.
The function used for the above process is pickle.dump().

Unpickling
Unpickling is the complete inverse of pickling. It deserializes the byte stream to recreate the objects stored in the file, and loads the object to memory.
The function used for the above process is pickle.load().

Note: Python has another, more primitive, serialization module called marshall, which exists primarily to support .pyc files in Python and differs significantly from pickle.

image

Related questions

0 votes
    Do Numpy And Scipy Support Python 3.x?...
asked Apr 25, 2021 in Technology by JackTerrance
0 votes
    What are the Difference between staticmethod and classmethod in Python?...
asked Jan 9, 2021 in Technology by JackTerrance
0 votes
    What is the difference between Python Arrays and lists?...
asked Dec 7, 2020 in Technology by JackTerrance
0 votes
    Explain split() and join() functions in Python?...
asked Dec 7, 2020 in Technology by JackTerrance
0 votes
    What is break, continue and pass in Python?...
asked Dec 6, 2020 in Technology by JackTerrance
0 votes
    What are global, protected and private attributes in Python?...
asked Dec 6, 2020 in Technology by JackTerrance
0 votes
    What are modules and packages in Python?...
asked Dec 6, 2020 in Technology by JackTerrance
0 votes
    What is the difference between xrange and range in Python?...
asked Dec 6, 2020 in Technology by JackTerrance
0 votes
    What is the difference between tuples and lists in Python?...
asked Nov 23, 2020 in Technology by JackTerrance
0 votes
    A Python package used in text analysis and natural language processing....
asked Oct 27, 2020 in Technology by Editorial Staff
0 votes
    Top 10 Python IDEs And Code Editors In 2020...
asked Oct 27, 2020 in Technology by Editorial Staff
0 votes
    Does Dataset API support Python and R. 1. yes 2. No...
asked Oct 22, 2020 in Technology by JackTerrance
0 votes
    What will be the output of the following Python code? >>>list1 = [1, 3] >>>list2 = list1 >>>list1[0] = 4 >>>print(list2) a) [1, 4] b) [1, 3, 4] c) [4, 3] d) [1, 3]...
asked Jan 2, 2023 in Technology by JackTerrance
0 votes
    What will be the output of the following Python code? print('*', "abcde".center(6), '*', sep='') a) * abcde * b) *abcde * c) * abcde* d) * abcde *...
asked Jan 2, 2023 in Technology by JackTerrance
0 votes
    To add a new element to a list we use which Python command? a) list1.addEnd(5) b) list1.addLast(5) c) list1.append(5) d) list1.add(5)...
asked Jan 2, 2023 in Technology by JackTerrance
...