python脚本来腌制整个环境 [英] python script to pickle entire environment

查看:79
本文介绍了python脚本来腌制整个环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Python REPL中工作,我想定期保存我的工作.有人有脚本来转储我定义的所有变量吗?我正在寻找这样的东西:

I'm working inside the Python REPL, and I want to save my work periodically. Does anybody have a script to dump all the variables I have defined? I'm looking for something like this:

for o in dir():
    f=open(o)
    pickle(o_as_object, f)

这似乎是其他人所做的事情,因此我想在重新发明轮子之前先问一下.

This seems like something other people have done, so I wanted to ask before re-inventing the wheel.

推荐答案

我认为您想要莳萝:

除了腌制python对象外,莳萝还提供了以下功能: 将解释器会话的状态保存在单个命令中.因此, 保存一个解释器会话,然后关闭 解释器,将腌制后的文件运送到另一台计算机,打开一个新 解释器,解开会话的会话,从而从保存"状态继续 原始解释程序会话的状态.

In addition to pickling python objects, dill provides the ability to save the state of an interpreter session in a single command. Hence, it would be feasable to save a interpreter session, close the interpreter, ship the pickled file to another computer, open a new interpreter, unpickle the session and thus continue from the 'saved' state of the original interpreter session.

请注意,它仍然处于Alpha状态,因此不要依赖它来存储关键数据.

Note that it's still in alpha, so don't rely on it to store critical data.

当然,有些事情无法恢复,例如打开文件句柄.但是你可以接近的.

Of course, some things can't be restored, such as an open file handle. But you can get quite close.

这篇关于python脚本来腌制整个环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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