ipython笔记本关闭后保存变量

mar*_*rkk 5 python ipython jupyter-notebook

关闭 ipython 笔记本后,我意识到所有代码都在那里,但名称空间已被重置,因为我拥有的所有变量都消失了。有没有办法可以保存变量,以便当我重新打开 ipython 笔记本时,变量都在那里,而无需重新运行代码?

Rob*_*obs 4

使用 storemagic 命令。
http://ipython.org/ipython-doc/rel-0.12/config/extensions/storemagic.html

In [1]: l = ['hello',10,'world']
In [2]: %store l
In [3]: exit

(IPython session is closed and started again...)

ville@badger:~$ ipython
In [1]: l
Out[1]: ['hello', 10, 'world']
Run Code Online (Sandbox Code Playgroud)

  • 看起来它只能与可挑选的变量一起使用 - 在我的例子中,它是一个不可挑选的“DataFrame” - 但这肯定很有用。谢谢! (2认同)