in Python by
What is pickling and unpickling in Python?

2 Answers

0 votes

Pickling is just the Python way of saying serializing. Pickling lets you serialize an object into a string (or anything else you choose) in order to be persisted on storage or sent over network. Unpickling is the process of restoring the original object from a pickled string.

Pickle is not secure. Only unpickle objects from trusted sources

Python docs

Here is how you would pickle a basic data structure:

import pickle

cars = {"Subaru": "best car", "Toyota": "no i am the best car"}

cars_serialized = pickle.dumps(cars)

# cars_serialized is a byte string

new_cars = pickle.loads(cars_serialized)

What are *args and **kwargs in Python functions?

These deal closely with unpacking. If you put *args in function’s parameter list, all unnamed arguments will be stored in the args array. **kwargs works the same way, but for named parameters:

def func1(*args, **kwargs):



func1(1, 'abc', lol='lmao')

> [1, 'abc']

> {"lol": "lmao"}

0 votes

Pickling is the process of converthing a Python object hierarachy into a byte stream for storing it into a database.It is also known as serialization. 

Unpickling is the reverse of pickling. The byte stream is conveted back into obhect hierarchy.

Click here to read more about Python
Click here to read more about Insurance

Related questions

0 votes
asked Jan 1 in Python by SakshiSharma
0 votes
asked Jun 12, 2020 in Python by Robindeniel
0 votes
asked Feb 11 in Python by SakshiSharma
0 votes
asked Jul 14, 2020 in Python by GeorgeBell
0 votes
asked Dec 19, 2019 in Python by sharadyadav1986