DavidC
DavidC

Reputation: 1441

batch execute iPython Notebook with command line argument?

I'm using nbconvert to execute an iPython notebook via the command line (as in this answer):

ipython nbconvert --to=html --ExecutePreprocessor.enabled=True RunMe.ipynb

Is it possible to pass command line arguments to be accessed from within the notebook (like sys.argv)?

This would let me reuse the same notebook in different contexts.

Upvotes: 16

Views: 5303

Answers (2)

GaryBishop
GaryBishop

Reputation: 3792

This is my attempt at a single module for argument parsing in Python scripts and Jupyter notebooks. It only supports minimalist key=value style arguments but meets my needs.

I nbconvert it to a Python script named Args.py and use it as shown.

Then I can batch run a notebook like:

jpn mynotebook limit=5 assignment=A2

Upvotes: 2

nitind
nitind

Reputation: 20033

You can access environmental variables instead. I have yet to come across a way to use command line arguments directly.

Upvotes: 11

Related Questions