问题描述
我想在循环传递参数中运行整个Jupyter笔记本.我可以通过麻烦的方式(带有附加组件)传递参数,如此处在jupyter/ipython笔记本中将命令行参数传递给argv .我可以用更简单的方式做吗?
I want to run whole Jupyter notebook in cycle passing parameters. I can pass parameters cumbersome way (with addons) as explained here Passing command line arguments to argv in jupyter/ipython notebook I guess. Can I do in more simple way?
推荐答案
在调用%run
之前,可以简单地在单元格中初始化参数(正在调用笔记本的变量).在通话笔记本中:
Parameters (variables of notebook being called) can simply be initialised in cell before %run
is called. In calling notebook:
for i in range (1,3):
for j in range (0,4):
param1 = i
param2 = j
%run ./foo.ipynb
为了能够在正在运行的笔记本中初始化这些变量,以便于单独使用(作为整体运行),可以在初始化之前检查变量是否存在.在foo.ipynb
:
In order to be able to initialise these variables in notebook being run to facilitate to be used separately (to run as whole) variables can be checked for existence before initialisation How do I check if a variable exists?. In foo.ipynb
:
if not 'param1' in locals():
param1 = 1
由于整个笔记本的多次运行输出都将放在一个单元格中,因此可能会启动自动滚动(默认情况下处于打开状态).要禁用它,请遵循例如在菜单cell
-> all output
-> toggle autoscrolling
中.
As output of several runs of whole notebook would be in one cell, autoscrolling (which is on by default) may kick in. To disable it follow Disable iPython Notebook Autoscrolling e.g. in menu cell
->all output
->toggle autoscrolling
.
这篇关于使用参数从另一个笔记本运行Jupyter笔记本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!