ArgumentParser() 存储bool类型有坑,不能直接传True/False,需要设置action。
‘store_true’ and ‘store_false’
- These are special cases of ‘store_const’ used for storing the values True and False respectively. In addition, they create default values of False and True respectively. For example:
parser = argparse.ArgumentParser()
parser.add_argument('--foo', action='store_true')
parser.add_argument('--bar', action='store_false')
parser.add_argument('--baz', action='store_false')
parser.parse_args('--foo --bar'.split())
Namespace(foo=True, bar=False, baz=True)
[1] Parser for command-line options, arguments and sub-commands