ipython notebook save variables after closing

2019-07-04 05:36发布

问题:

After you close the ipython notebook, I realized all the code is there but the namespace has been reset, as in all of the variables I had were gone. Is there a way I could save the variables so that when I turn ipython notebook back on, the variables are all there without rerunning the code?

回答1:

Use the storemagic command.
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']