Re: storing variables *in* the notebook
Zoltán Vörös <[email protected]> Fri, 27 Jan 2017 18:39:23 +0100
| Newsgroups | gmane.comp.python.ipython.devel |
|---|---|
| Message-ID | <[email protected]> |
On 01/27/2017 05:53 PM, Kiko wrote:
>
> 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)
Thanks for the pointer! I have already figured that I could re-use the
code in the notebook extension 'toc2', and that of %store magic, but
here you present a more or less complete solution. Thanks!
Zoltán