What difference between pickle and _pickle in python 3?

前端 未结 2 1693
没有蜡笔的小新
没有蜡笔的小新 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:54

    From the Library Changes section of the What's New In Python 3.0 documentation:

    A common pattern in Python 2.x is to have one version of a module implemented in pure Python, with an optional accelerated version implemented as a C extension; for example, pickle and cPickle. This places the burden of importing the accelerated version and falling back on the pure Python version on each user of these modules. In Python 3.0, the accelerated versions are considered implementation details of the pure Python versions. Users should always import the standard version, which attempts to import the accelerated version and falls back to the pure Python version. The pickle / cPickle pair received this treatment. The profile module is on the list for 3.1. The StringIO module has been turned into a class in the io module.

    Since it is a python convention that implementation details are prepended with an underscore, cPickle became _pickle. Notably this means that if you are importing _pickle, the API has no guaranteed contract and could break backwards-compatibility in future releases of python3, as unlikely as that may be.

提交回复
热议问题