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

Zoltán Vörös zvoros at gmail.com
Thu Jan 26 16:32:38 EST 2017


Hi Matthias,


On 01/26/2017 10:03 PM, Matthias Bussonnier wrote:
> If I were you I would go the route of a custom ContentManager which
> expose actual folders as notebooks (something akin ipymd/notedown but
> with folders) and start kernels in these folders.
> Then you "just" zip and share the folder. That would also solve the
> fact that notebooks are text-based fileformats, which are inherently
> bad for binary data, andd o not support incremental updates.

If the data are pickled, then one wouldn't have to save anything in 
binary format. All I want to do is write a single ascii line in the 
metadata if the notebook. That in itself is actually recommended (From 
the help: " We recommend putting custom metadata attributes in an 
appropriately named sub-structure, so they don't conflict with those of 
others."), and supports incremental updates. This magic command or 
whatever would simply save the step of having to open the metadata 
editor manually, and inserting the line by hand.

> One of the problem is that what you are trying to do will not work on
> many system and it is relatively hard to make it part of Jupyter if it
> only work on some limited use case as we'd like to have a clear
> message of what is vetted by the core.

I am not sure I see the difficulty: this would be pure python, pure 
javascript. You take the variable, pickle it, attach the resulting 
string to the notebook metadata under "user_variables", and you are 
done. Of course, it is a different question, what happens, if your 
kernel is not python. Well, then it's a problem, I admit. But there are 
other magic commands that are python specific, e.g., prun, or the 
debugger, so this in itself can't be an obstacle.

I have looked at the documentation, but it seems to me that no functions 
could expose the notebook metadata, or the cell metadata for that 
matter, is that correct? (I don't want to divert the discussion, but 
this latter functionality could be used for creating plots/tables etc. 
with caption in the notebook. The caption would be displayed in the 
notebook as an extra div, and the content of the caption could be 
written in the cell metadata. Nbconvert could then strip the div from 
the output, and take the raw content of the metadata, and insert it in 
the LaTeX document. Captions for figures are a long-standing problem in 
the notebook.)



Cheers,
Zoltán





More information about the IPython-dev mailing list