# %load_ext autoreload
# %autoreload 2
from notebook_autorun import Autorun
cells = '3,-1'
Autorun(cells=cells, metadata=False, comment=False, focus=None, verbose=True).add_js()
# in nbviewer.org the Javascript object (code) and Markdown object (status msg) are displayed
# as there is no security mechanism disabling their execution - as opposed to the real notebook
# So you should see the following, instead of the actual status message:
#
#<IPython.core.display.Javascript object>
#
#<IPython.core.display.Markdown object>
If you see <IPython.core.display.Javascript object> below, this notebook is not trusted. As a consequence Autorun cannot work. Run "from notebook_autorun import Autorun; Autorun.info()" for more info.
This output cell contains notebook-autorun settings:
{"str_cells": null, "metadata": true, "comment": false, "comment_flag": "# AUTORUN"}
# manually executed after previous cell failure and indication
from notebook_autorun import Autorun; Autorun.info()
This module enables auto-run of certains cells at notebook kernel start.
It will work only for trusted notebooks.
The cells to autorun can be determined by one of the 3 args below.
Only one of them must be specified:
cells
: List of 0-indexed cells or String representing a list of cells. Python list slices are allowed. Default is None
. cells
is stringified to str_cells
before passing to javascript. Invalid cell numbers (e.g. greater than the notebook number of cells) are ignored. Examples: [2, 3], '2,3', '2:', ':-2', '4:8', '::-1'metadata
: Boolean (default is False
). If True
, all cells with medatada "autorun": true
are concerned.comment
: Boolean (default is False
). If True
, all cells containing a comment comment_flag
(default is # AUTORUN
) are concerned.Because a notebook is designed to allow the user to write arbitrary code, it has full access to many resources.
The typical risks are the following:
See the Security in notebook documents section of the official Jupyter Notebook documentation for more info.
Therefore you should review and must trust the notebook before you can use notebook-autorun.
i = 11; print(i); i += 1
print(i); i += 1
print(i); i += 1
print(i); i += 1
print(i); i += 1