How to pass command line arguments in IPython jupyter notebook

白昼怎懂夜的黑 提交于 2019-12-22 08:03:42

问题


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)

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.


回答1:


You can use argparse argument with class syntax like this in jupyter.

class Args:
  test_name = ''
  symbolSet = 'defaultOne'

args=Args()

and there is a auto transformation script.
http://35.192.144.192:8000/arg2cls.html



来源:https://stackoverflow.com/questions/43057529/how-to-pass-command-line-arguments-in-ipython-jupyter-notebook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!