python argparse sys.argv
1 class WeiLearningArgumentParser(argparse.ArgumentParser): 2 def __init__(self, 3 prog=None, 4 usage=None, 5 description='[CONFIG_FILE_NAME] [ID]', 6 epilog=None, 7 version=None, 8 parents=[], 9 formatter_class=argparse.HelpFormatter, 10 prefix_chars='-', 11 fromfile_prefix_chars=None, 12 argument_default=None, 13 conflict_handler='error', 14 add_help=True): 15 argparse.ArgumentParser.__init__(self, 16 prog, 17 usage, 18 description, 19 epilog, 20 version, 21 parents, 22 formatter_class, 23 prefix_chars, 24 fromfile_prefix_chars, 25 argument_default, 26 conflict_handler, 27 add_help) 28 29 def init_arguments(self): 30 self.add_argument("config_file", metavar = "config_file", type= str, default='conf/weilearn.xml', 31 help= "the config_file of weilearn depends on. ") 32 self.add_argument('node_id', metavar = "node_id", type=int, default= 1, 33 help= 'the id of node which start weilearn.') 34 35 def parse_args(self, args = None): 36 if args is None: 37 args = sys.argv[1:] 38 if len(args) < 2: 39 args = ['-h'] 40 args = argparse.ArgumentParser.parse_args(self, args) 41 return args