avatar Bite 317. Pickling objects

In this Bite you will load (deserialize) and dump (serialize) a data structure from / to a pickle file which support storing your own objects, interesting!

As compared to JSON pickle is a binary serialization format, so it's not human-readable. It can represent an extremely large number of Python types. On the flip side though, deserializing untrusted JSON does not in itself create an arbitrary code execution vulnerability, pickle does which makes it unsecure.

Complete the two following functions to (un)pickle data:

1. deserialize: loads in the passed in pickle file path and returns the data structure it retrieves from it (a list of namedtuples).

2. serialize: takes a pickle file path to pickle the data to. It's either the data passed in (second argument) or, if no data is provided (data is None), it calls deserialize to get the default data (again a list of namedtuples).

We hope this Bite gets you up2speed with serializing data using the pickle module.

Login and get coding
go back Beginner level
Bitecoin 2X

137 out of 139 users completed this Bite.
Will you be the 138th person to crack this Bite?
Resolution time: ~31 min. (avg. submissions of 5-240 min.)
Our community rates this Bite 2.5 on a 1-10 difficulty scale.
» You can do it! 😌

Focus on this Bite hiding sidebars, turn on Focus Mode.

Ask for Help