Proko
Proko

Reputation: 2021

Run python code from stdin with additional script arguments in PowerShell

The use case is the following:

  1. convert jupyter notebook to python
  2. run converted notebook on-the fly with additional arguments

What I have tried so far:

jupyter nbconvert --to python --stdout .\some_nb.ipynb | python

some_nb.ipynb awaits for arguments via argparse so normally I would do something like:

python some_nb.py --argument_one=1 

When I do that:

jupyter nbconvert --to python --stdout .\some_nb.ipynb | python --argument_one=1

argument_one is of course binded to python and I am not sure how to properly pipeline this.

Upvotes: 1

Views: 161

Answers (1)

Proko
Proko

Reputation: 2021

Finally got it. Python has - argument after which it reads arguments from stdin

https://docs.python.org/3/using/cmdline.html

jupyter nbconvert --to python --stdout .\some_nb.ipynb| python - --argument_one=1

Upvotes: 1

Related Questions