如何在IPython Jupyter Notebook中传递命令行参数 [英] How to pass command line arguments in IPython jupyter notebook
问题描述
我是Ipython的新手.目前,我已经使用Anaconda安装了Ipython,并使用jupyter笔记本UI编写了代码以绘制图表. 我想借助argparse模块将少量参数传递给我的工作脚本. 下面是代码.
I a new to Ipython. Currently i have installed Ipython using Anaconda and writing a code to plot chart using jupyter notebook UI. I want to pass few arguments to my working script with the help of argparse module. below is the code..
import argparse
parser = argparse.ArgumentParser(description = 'Process display arguments')
parser.add_argument('-t', "--test_name", help="Mandatory test name directory path", type=str)
parser.add_argument('-s', "--symbolSet", nargs = '?', help="Optional symbolset", const = 'baz', default = 'deafultOne')
args = parser.parse_args()
if args.test_name is None:
print("test_name argument is mandatory.. Use option -h for help.. Exiting..")
sys.exit(1)
现在如何在通过UI执行脚本时如何传递这些参数,或者如何通过命令提示符运行脚本并仍然能够绘制图表? 我正在Windows机器上工作.如果您需要更多信息,请告诉我.对此.
Now how can I pass these arguments while executing my script through UI or can I run my script through command prompt and still be able to draw the chart? I am working on windows machine. Please let me know if you need more info. on this.
推荐答案
您可以在jupyter中将argparse参数与此类语法一起使用.
You can use argparse argument with class syntax like this in jupyter.
class Args:
test_name = ''
symbolSet = 'defaultOne'
args=Args()
,并且有一个自动转换脚本.
http://35.192.144.192:8000/arg2cls.html
and there is a auto transformation script.
http://35.192.144.192:8000/arg2cls.html
这篇关于如何在IPython Jupyter Notebook中传递命令行参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!