Executing Javascript cells in Jupyter Notebooks

寵の児 提交于 2019-12-07 04:08:23

问题


I'm seeing some strange behavior using Javascript cells in a (trusted) Jupyter notebook.

For example, I can execute the following cells, intended to fetch the current URL of the notebook.

%%javascript
var kernel = IPython.notebook.kernel;
var thename = window.location.href;
var command = "notebook_url = " + "'"+thename+"'";
kernel.execute(command);

And now I try to access the variable in another cell:

print notebook_url

This works as expected with I run the cells one after another (Shift + Enter), but throws a NameError: name 'notebook_url' is not defined when I try to 'Run All' cells.

How could I get this to work with 'Run All'?

来源:https://stackoverflow.com/questions/30745228/executing-javascript-cells-in-jupyter-notebooks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!