以编程方式执行Jupyter Notebook单元 [英] execute a Jupyter Notebook cell programmatically

查看:113
本文介绍了以编程方式执行Jupyter Notebook单元的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Jupyter Notebook单元是否可以以编程方式执行另一个单元? (即使用Python)

Is it possible for a Jupyter Notebook cell to execute another cell programmatically? (i.e. using Python)

如果这样,是否可以指定要执行的单元号?

And if so, is it possible to specify the cell number to execute?

推荐答案

有一个名为execute_cells的javascript函数,当给定单元格索引列表时,这些函数将运行这些单元格.

There is a javascript function called execute_cells that when given an list of cell indices runs those cells.

%%javascript
Jupyter.notebook.execute_cells([0]) # 0 to run first cell in notebook etc.

如果您需要在Python代码单元中专门运行它,可以使用IPython.display模块中的Javascript函数来执行javascript

If you need to run it specifically in a Python code cell, one can use the Javascript function in the IPython.display module to execute javascript

from IPython.display import Javascript
Javascript("Jupyter.notebook.execute_cells([2])")

请参阅: https://github.com/jupyter/notebook/blob/881268f64245e0829173d1a6dc7aad7db39795d3/notebook/static/notebook/js/notebook.js#L2407

这篇关于以编程方式执行Jupyter Notebook单元的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆