Python2: Should I use Pickle or cPickle?

PythonSerializationPicklePython 2.x

Python Problem Overview


Python 2 has both the pickle and cPickle modules for serialization.

cPickle has an obvious advantage over pickle: speed. What, if any, advantage does pickle have over cPickle?

Python Solutions


Solution 1 - Python

The pickle module implements an algorithm for turning an arbitrary Python object into a series of bytes. This process is also called serializing” the object. The byte stream representing the object can then be transmitted or stored, and later reconstructed to create a new object with the same characteristics.

The cPickle module implements the same algorithm, in C instead of Python. It is many times faster than the Python implementation, but does not allow the user to subclass from Pickle. If subclassing is not important for your use, you probably want to use cPickle.

Source of above information.

Solution 2 - Python

I found this regarding pickle and cPickle:

"The pickle module implements an algorithm for turning an arbitrary Python object into a series of bytes....

The cPickle module implements the same algorithm, in C instead of Python. It is many times faster than the Python implementation, but does not allow the user to subclass from Pickle.

If subclassing is not important for your use, you probably want to use cPickle."

Source: https://pymotw.com/2/pickle/

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser200783View Question on Stackoverflow
Solution 1 - PythonrkatkamView Answer on Stackoverflow
Solution 2 - PythonCharlton LaneView Answer on Stackoverflow