I want to run a full Jupyter notebook in a cycle, passing different parameters for each run of the notebook. I can pass parameters with addons as explained here: Passing command line arguments to argv in jupyter/ipython notebook, but this seems overly cumbersome. Is there a more simple and straight-forward way of doing this?
Asked
Active
Viewed 6,661 times
1 Answers
8
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
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
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
.

Alex Martian
- 3,423
- 7
- 36
- 71