Pickle Python 序列化 [英] Pickle Python Serialization

查看:43
本文介绍了Pickle Python 序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通俗地说,什么是序列化",我为什么需要它?我阅读了维基百科条目,但仍然不明白.为什么我需要将数据转换成位序列来存储在文件中?我特别关注使用 Python 的 pickle 模块进行序列化.

In layman's terms, what is "Serialization", and why do I need it? I read the Wikipedia entry, but still don't understand it. Why do I need to convert data into a sequence of bits to store it in a file? I am specifically concerned with using Python's pickle module to do serialization.

感谢您抽出宝贵时间!

推荐答案

您可以保存程序的状态(特定对象的).想象一下,您有一个运行数小时甚至数天的程序.使用pickle,您可以保存计算状态,终止程序并在以后继续计算(如果需要).

You can save the state of a programm (of specific objects). Imagine you have a program which runs for many hours or even days. Using pickle you can save the state of the calculation, kill the programm and resume the calculation later if you want to.

您甚至可以通过电子邮件将保存的对象发送给其他人,他们可以继续计算或查看您的结果.

You could even email the saved objects to other people, who than can resume the calculation or view your results.

我有时会挑选用户偏好或(在测验中)上次问的问题以及给出的答案.

I sometimes pickle userpreferences or (in a quiz) what questions where asked the last time and what answers were given.

这篇关于Pickle Python 序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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