运行 python 来自 stdin 的代码以及 PowerShell 中的附加脚本参数
Run python code from stdin with additional script arguments in PowerShell
用例如下:
- 将 jupyter notebook 转换为 python
- 运行 使用附加参数即时转换笔记本
到目前为止我尝试过的:
jupyter nbconvert --to python --stdout .\some_nb.ipynb | python
some_nb.ipynb
通过 argparse
等待参数所以通常我会做这样的事情:
python some_nb.py --argument_one=1
当我这样做时:
jupyter nbconvert --to python --stdout .\some_nb.ipynb | python --argument_one=1
argument_one
当然绑定到 python
,我不确定如何正确地传递它。
终于明白了。 Python 有 -
个参数,之后它从 stdin
读取参数
https://docs.python.org/3/using/cmdline.html
jupyter nbconvert --to python --stdout .\some_nb.ipynb| python - --argument_one=1
用例如下:
- 将 jupyter notebook 转换为 python
- 运行 使用附加参数即时转换笔记本
到目前为止我尝试过的:
jupyter nbconvert --to python --stdout .\some_nb.ipynb | python
some_nb.ipynb
通过 argparse
等待参数所以通常我会做这样的事情:
python some_nb.py --argument_one=1
当我这样做时:
jupyter nbconvert --to python --stdout .\some_nb.ipynb | python --argument_one=1
argument_one
当然绑定到 python
,我不确定如何正确地传递它。
终于明白了。 Python 有 -
个参数,之后它从 stdin
https://docs.python.org/3/using/cmdline.html
jupyter nbconvert --to python --stdout .\some_nb.ipynb| python - --argument_one=1