rasbt/watermark

information on current notebook filename?

jhconning opened this issue · 4 comments

Does watermark include an option to include the notebook filename in the watermark magic output? I could not find such an option in the documentation.

If this is not currently possible, it would be an extremely useful feature to add.

By default a notebook printed out using the _File _PrintPreview option does not print the filename in the header or footer. I was looking at printouts from a couple weeks ago and watermark provides details about the hardware/software environment and date/time printed, but no an answer to the all important question of the name of the notebook, to know what file to return to.

From this stackoverflow discussion there seem to be ways to have the filename printed in a cell but none of the proposed solutions are compact or elegant. So it would be great if watermark could do the work behind the scenes.

Thanks for a great tool that I use daily.

**update: ** the jupyter notebook contributors appear to be discussing a similar issue jupyter/notebook#1000

rasbt commented

Thanks for the suggestion, it sounds useful to me. Yeah, something like this:

import os
from IPython.core.display import Javascript
from IPython.display import display

display(Javascript('Jupyter.notebook.kernel.execute(\
                       "this_notebook = " + "\'"\
                       +Jupyter.notebook.notebook_name+"\'");'))

os.path.abspath(this_notebook)

would work. Not sure how robust it is, but I can add it to watermark.

Thanks, looking forward to it. It is a feature that would make this already essential extension ...indispensable.

rasbt commented

Yeah, I will probably find it useful myself sometimes (I usually have too many jupyter notebooks open all at once, and this could quickly tell me where they are located ;)). Shouldn't be complicated to add, will try to get to it in the next few days!

rasbt commented

Hm, tried the workaround proposed in jupyter/notebook#1000, but it doesn't worked when I moved to the module (due to the different namespace as mentioned in the thread). I guess the only thing we can do now is to wait until some attribute with file path information gets added to Jupyter notebook or so. I will leave this open to come back to it with a solution some day