What difference between pickle and _pickle in python 3?

前端 未结 2 1694
没有蜡笔的小新
没有蜡笔的小新 2020-12-05 22:54

I am new in python and want implement fast object serialization. I was trying to use json, but it was too slow, also was trying to use marshall module, but

2条回答
  •  天涯浪人
    2020-12-05 23:48

    The pickle module already imports _pickle if available. It is the C-optimized version of the pickle module, and is used transparently.

    From the pickle.py source code:

    # Use the faster _pickle if possible
    try:
        from _pickle import *
    except ImportError:
        Pickler, Unpickler = _Pickler, _Unpickler
    

    and from the pickle module documentation:

    The pickle module has an transparent optimizer (_pickle) written in C. It is used whenever available. Otherwise the pure Python implementation is used.

    In Python 2, _pickle was known as cPickle, but has been updated to allow the transparent use as an implementation detail.

提交回复
热议问题