为什么我必须多次执行javascript单元才能让它们在Jupyter笔记本中工作?

时间:2016-06-01 16:54:18

标签: jupyter-notebook

这段代码将为我提供运行它的Ipython笔记本的名称,

# Create a variable in Javascript that we use in Python
display(Javascript('IPython.notebook.kernel.execute("theNotebook = " + "\'"+IPython.notebook.notebook_name+"\'");'))
theNotebook

但是我必须在给出正确答案之前执行该单元2-3次。我第一次运行它时得到:

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-3-e65ff4ccad73> in <module>()
      1 # Create a variable in Javascript that we use in Python
      2 display(Javascript('IPython.notebook.kernel.execute("theNotebook = " + "\'"+IPython.notebook.notebook_name+"\'");'))
----> 3 theNotebook

NameError: name 'theNotebook' is not defined

然后我第二次得到:

'techela.ipynb'

我做错了吗?

0 个答案:

没有答案