Seen bug in argparse module

Jagdish Choudhary jagdish1287 at gmail.com
Fri Jun 24 14:40:29 EDT 2016


Hi All,


When argument provided from user which doesn't match to right option which
is mentioned in help , it runs without issue..let me provide an example

https://docs.python.org/3.3/library/argparse.html

import argparse
parser = argparse.ArgumentParser(description='Process some
integers.')parser.add_argument('integers', metavar='N', type=int,
nargs='+',
                   help='an integer for the
accumulator')parser.add_argument('--sum', dest='accumulate',
action='store_const',
                   const=sum, default=max,
                   help='sum the integers (default: find the max)')
args = parser.parse_args()print(args.accumulate(args.integers))

python prog.py -h
usage: prog.py [-h] [--sum] N [N ...]

Process some integers.

positional arguments:
 N           an integer for the accumulator

optional arguments:
 -h, --help  show this help message and exit
 --sum       sum the integers (default: find the max)

If user run it like below-

JAGDISHs-MacBook-Pro:test_python jagdish$ python prog.py 12 3 4 --sum
19
JAGDISHs-MacBook-Pro:test_python jagdish$ python prog.py 12 3 4 --su
19
JAGDISHs-MacBook-Pro:test_python jag


-- 
Thanks and Regards,
Jagdish Choudhary
IBM India Pvt Ltd, Bangalore
M.No-8971011661


More information about the Python-list mailing list