Python2: Should I use Pickle or cPickle?

后端 未结 2 744
南旧
南旧 2021-02-04 23:44

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

cPickle has an obvious advantage over pickle: spe

相关标签:
2条回答
  • 2021-02-05 00:12

    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.

    0 讨论(0)
  • 2021-02-05 00:31

    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/

    0 讨论(0)
提交回复
热议问题