jupyter ipython_在jupyter / ipython notebook中将命令行参数传递...
时间: 2023-07-03 22:11:45 浏览: 179
您可以使用`argparse`模块来将命令行参数传递给Jupyter/IPython notebook。以下是一个示例代码:
```python
import argparse
import sys
parser = argparse.ArgumentParser()
parser.add_argument('--arg1', type=str, help='argument 1')
parser.add_argument('--arg2', type=int, help='argument 2')
args = parser.parse_args(sys.argv[1:])
print('arg1:', args.arg1)
print('arg2:', args.arg2)
```
在Jupyter/IPython notebook中,您可以使用`%run`命令来运行此代码,并传递命令行参数。例如:
```
%run my_script.py --arg1 value1 --arg2 2
```
这将在notebook中运行`my_script.py`脚本,并将`--arg1`和`--arg2`参数传递给它。输出将显示在notebook中。
阅读全文
相关推荐









