6

I want to store currently running Jupyter notebook name in python variable. I create 2 cells

from IPython.display import display,Javascript 
Javascript('IPython.notebook.kernel.execute("notebook_name = " + "\'"+IPython.notebook.notebook_name+"\'");')

and

notebook_name

This works fine if I execute cells one after another, but I mostly execute cells with "run all cells" command, and in this case I get the error:

NameError: name 'notebook_name' is not defined

I get the same error if I unite previous 2 cells into 1 cell. I believe this is due to synchronization between python and JavaScript. Any help is appreciated.

Apogentus
  • 6,371
  • 6
  • 32
  • 33
  • 1
    It seems [comment to this question](https://stackoverflow.com/questions/30745228/executing-javascript-cells-in-jupyter-notebooks#comment49593645_30745228) answers your question – dehiker Apr 17 '19 at 12:18
  • 1
    related: https://stackoverflow.com/questions/12544056/how-do-i-get-the-current-ipython-jupyter-notebook-name – matth Mar 19 '20 at 08:58

0 Answers0