gpt4 book ai didi

python脚本来 pickle 整个环境

转载 作者:太空狗 更新时间:2023-10-30 01:23:55 24 4
gpt4 key购买 nike

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

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

这好像是其他人做过的事情,所以我想在重新发明轮子之前问一下。

最佳答案

我想你想要Dill :

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 阶段,因此不要依赖它来存储关键数据。

当然,有些东西是无法恢复的,比如打开的文件句柄。但您可以非常接近。

关于python脚本来 pickle 整个环境,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8232798/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com