Quantcast
Channel: Planet Python
Viewing all articles
Browse latest Browse all 23776

Artem Golubin: How does pickle work in Python?

$
0
0

The pickle module implements serialization protocol, which provides an ability to save and later load Python objects using special binary format. Unlike json, pickle is not limited to simple objects. It can also store references to functions and classes, as well as the state of class instances.

Before we start, it is worth mentioning, that there are two versions of modules: pickle and `cPickle. The latter is faster and implements the same algorithm but in C. The downside of this is that you cannot inherit pickle's classes.

Pickle example

importpickleimportpickletoolsclassNode:def__init__(self,data):self.data=dataself.children=[]defadd_child(self,obj ...

Viewing all articles
Browse latest Browse all 23776

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>