python - How to Check if an Argument Was Called Without an Action? -
i want able see if argument called without using store action. instead of code looking this:
parser = argparse.argumentparser() parser.add_argument('-a', '--argument', action="store", dest="some_arg", help='help data..', default="none") args = parser.parse_args() if args.some_arg == "user input": print "argument called." i want user not have enter in "user input" same result print "argument called". in other words if user wanted reference argument have type:
script.py --argument instead of:
script.py --argument user input
you can use store_true action. set value true if argument specified, or false otherwise:
parser = argparse.argumentparser() parser.add_argument('--foo', action='store_true') args = parser.parse_args() if args.foo: print('--foo specified')
Comments
Post a Comment