简体   繁体   English

使用 PowerShell 中的附加脚本 arguments 从标准输入运行 python 代码

[英]Run python code from stdin with additional script arguments in PowerShell

The use case is the following:用例如下:

  1. convert jupyter notebook to python将 jupyter 笔记本转换为 python
  2. run converted notebook on-the fly with additional arguments使用额外的 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: some_nb.ipynb通过argparse等待 arguments 所以通常我会做类似的事情:

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. argument_one当然绑定到python ,我不知道如何正确地流水线化。

Finally got it.终于明白了。 Python has - argument after which it reads arguments from stdin Python 有-参数,之后它从标准输入读取 arguments

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM