[IPython-dev] storing variables *in* the notebook
Zoltán Vörös
zvoros at gmail.com
Wed Jan 25 16:33:47 EST 2017
Hi all,
This question has been raised a couple of times at various places, but I
haven't yet found the answer I was looking for. In short, I would like
to store the value of some variables in the notebook itself. The
typical, and almost exclusively mentioned, use-case is something like this:
In [320]: x = some_long_calculation(33)
and then the user would like to be able to re-use x in a new session,
without having to call some_long_calculation() again. Even worse is,
perhaps, the case
In [321]: x = some_long_measurement()
when the value of x cannot, even in principle, be recovered by simply
re-running the notebook, because some_long_measurement() collects
experimental data through a measurement device.
Now, the standard answer to this problem is the %store magic, but that
has at least two problems (one is actually more like a feature). First,
as far as I understand, it saves the variable into a separate file,
therefore, the notebook itself is not "portable" anymore: if I want to
give it to someone, or use it on another computer, then I need the extra
file, but then I could just save the variable in a file in the first place.
Second, if two sessions store the same variable, then, well, then it
will be over-written, which is probably not ideal (but can qualify as a
feature).
So, I would like to ask, whether it is possible to attach the value of
simple variables to the metadata of the notebook, and recover it from
there. If there is no infrastructure for this, is this advisable at all,
and what would it take to implement it? Basically, what I am after is
very similar to store, but the target would be the notebook itself.
Cheers,
Zoltán
More information about the IPython-dev
mailing list