目前--resize我创建的标志是boolean,意味着我的所有对象都将被调整大小:
parser.add_argument("--resize", action="store_true", help="Do dictionary resize")
# ...
# if resize flag is true I'm re-sizing all objects
if args.resize:
for object in my_obects:
object.do_resize()
Run Code Online (Sandbox Code Playgroud)
有没有办法实现argparse参数,如果传递为boolean flag(--resize)将返回true,但如果传递value(--resize 10),将包含值.
例:
python ./my_script.py --resize # Will contain True that means, resize all the objectspython ./my_script.py --resize <index> # Will contain index, that means resize only specific object