How to pass command line arguments in IPython jupy

2019-05-04 09:14发布

问题:

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