• It also behaves similar to “store_true” action. • Now here’s a demonstration of what the “count” action gives. You’ve probably seen this sort of usage before. • And if you don’t specify the$_{-v}$ flag, that flag is considered to have$_{None}$ value. • As should be expected, specifying the long form of the flag, we should get the same output. • Sadly, our help output isn’t very informative on the new ability our script has acquired, but that can always be fixed by improving the documentation for our script (e.g. via the help keyword argument). • That last output exposes a bug in our program. Let’s fix: And this is what it gives: Let’s fix that bug: • First output went well, and fixes the bug we had before. That is, we want any value >= 2 to be as verbose as possible. • Third output not so good. 9 import argparse parser =argparse.ArgumentParser() parser.add_argument( "square",type=int, help="display a square of a given number ") parser.add_argument( "-v ","--verbosity ", action="count", default =0, help="increase output verbosity ") args =parser.parse_args() answer =args.square**2 if args.verbosity >=2: print("the square of {} equals {} ".format(args .square, answer)) elif args.verbosity >=1: print(" {} ^2 == {} ".format(args .square, answer)) else : print(answer) $ python3 prog.py 4-vvv the square of 4 equals 16 $ python3 prog.py 4-vvvv the square of 4 equals 16 $ python3 prog.py 4 Traceback (most recent call last): File "prog.py", line 11, in <module> if args.verbosity >= 2: TypeError: '>=' not supported between instances of 'NoneType' and 'int' import argparse parser =argparse.ArgumentParser() parser.add_argument( "square",type=int, help="display a square of a given number ") parser.add_argument( "-v ","--verbosity ", action="count", help="increase output verbosity ") args =parser.parse_args() answer =args.square**2 # bugfix: replace == with >= if args.verbosity >=2: print("the square of {} equals {} ".format(args .square, answer)) elif args.verbosity >=1: print(" {} ^2 == {} ".format(args .square, answer)) else : print(answer)