54

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?

0-_-0
  • 1,313
  • 15
  • 15
user200783
  • 13,722
  • 12
  • 69
  • 135
  • you may take look at this page. This will give you a proper direction about your confusion https://docs.python.org/2/library/pickle.html – Md Mehedi Hasan May 09 '16 at 10:12

2 Answers2

65

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.

rkatkam
  • 2,634
  • 3
  • 18
  • 29
  • 1
    For those searching for pickle / cPickle use in Python3, [this SO answer](https://stackoverflow.com/a/37138791/6340496) might be helpful. – S3DEV Oct 29 '20 at 09:42
  • 1
    From the link above, @Martijn Pieters: "In Python 3 the accelerated version has been integrated and there is simply no reason to use anything other than import pickle." – Dave Liu Sep 15 '21 at 20:05
9

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/

Charlton Lane
  • 438
  • 9
  • 13