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

Kiko kikocorreoso at gmail.com
Fri Jan 27 11:53:10 EST 2017


2017-01-27 16:16 GMT+01:00 Kiko <kikocorreoso at gmail.com>:

>
>
>>>
>> I can't tell why, but somehow this idea seems a bit familiar to me...
>>
>> Aha.
>
> Ok, I read the thread diagonally and my2cents ideas are already there...
>
> Sorry for the noise :-P
>
An example about how to write to your metadata. This should provide some
hints to create a line magic to do so:

from IPython.display import Javascript

x = [1,2,3]

def add_metadata(var_name, var):
    js = """
if (Jupyter.notebook.metadata['stored'] ===
undefined){{Jupyter.notebook.metadata['stored'] = {{}}}}
Jupyter.notebook.metadata['stored']['{var_name}']={var_content_serialised}
"""
    return Javascript(js.format(var_name=var_name,
var_content_serialised=var.__repr__()))

add_metadata('x', x)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20170127/47b32954/attachment.html>


More information about the IPython-dev mailing list