Search code examples
pythonpowershellpipeline

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.


Solution

  • 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