Pickle with custom classes

It is because you are setting Test.A as a class attribute instead of an instance attribute. Really what is happening is that with the test1.py, the object being read back from the pickle file is the same as test2.py, but its using the class in memory where you had originally assigned x.A. When your data … Read more

Understanding Pickling in Python

The pickle module implements a fundamental, but powerful algorithm for serializing and de-serializing a Python object structure. Pickling – is the process whereby a Python object hierarchy is converted into a byte stream, and Unpickling – is the inverse operation, whereby a byte stream is converted back into an object hierarchy. Pickling (and unpickling) is … Read more

Python pickle protocol choice?

Use the latest protocol that supports the lowest Python version you want to support reading the data. Newer protocol versions support new language features and include optimisations. From the pickle module data format documentation: There are currently 6 different protocols which can be used for pickling. The higher the protocol used, the more recent the … Read more