Python2:我应该使用Pickle还是cPickle? [英] Python2: Should I use Pickle or cPickle?

查看:131
本文介绍了Python2:我应该使用Pickle还是cPickle?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Python 2具有用于序列化的picklecPickle模块.

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

cPickle相对于pickle具有明显的优势:速度. picklecPickle有什么优势?

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

推荐答案

pickle 模块实现了将任意 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.

cPickle 模块在 C 中实现相同的算法,而不是Python.它比Python实现快很多倍,但不允许用户从Pickle继承子类.如果子类化对您的使用不重要,则可能要使用cPickle.

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.

以上信息的来源.

这篇关于Python2:我应该使用Pickle还是cPickle?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆