[IPython-dev] storing variables *in* the notebook

Klymak Jody jklymak at gmail.com
Thu Jan 26 16:06:12 EST 2017


> I think this goes far beyond what I had in mind. I think this function or whatever would just be
> 
> In [221]: x = long_calculation()  # x is 42
>                %store_in_notebook x
> 
> and in the new session
> 
> In [1]: %store_in_notebook -restore_variables
> In [2]: x
> Out [2]: 42

For my taste, I’d just save that result in a file (`pickle` or `shelf`, or netcdf if I wanted to be formal).  Its a lot more transparent what is going on.  

Imagine this case:  I `%store_in_notebook` the results of a long calculation, and then remove that code from the notebook for some reason.  I might very well wonder a year from now why my notebook is 50 Gb, and have no documentation of how it got that way.  

However, if you do have a whole slew of variables you suddenly want to save, did you try `dill`? 

import dill
import numpy as np

filename= 'globalsave.pkl'

if 1:
    x = np.arange(20)
    dill.dump_session(filename)
else:  
    dill.load_session(filename) 

Cheers,  Jody




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20170126/10021b66/attachment.html>


More information about the IPython-dev mailing list