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?
Asked
Active
Viewed 6,481 times
4
-
1I don't really know, but IPython launches python kernels, which are killed when you shut it down and therefore, all vcariables vanish. I don't know if IPython has a mechanism to store variables (kinda doubt it), but you could `pickle` the variables you need manually (like in the last cell of the notebook) and load them (also with pickle) in tbe first cell. Hower, thats why you have `run all` option to avoid this. I run machine learning programs and sometimes I do use `pickle` to store learned classifier (complex/time consuming results). – Imanol Luengo Aug 25 '15 at 18:25
1 Answers
3
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']

Robert Jacobs
- 3,266
- 1
- 20
- 30
-
2It seems like it can only work with pickeable variables - in my case it was a `DataFrame` which isn't pickleable - but this would definitely be useful. Thanks! – markk Aug 25 '15 at 20:01