Lines Matching full:verbosity
231 parser.add_argument("--verbosity", help="increase output verbosity")
233 if args.verbosity:
234 print "verbosity turned on"
240 $ python prog.py --verbosity 1
241 verbosity turned on
244 usage: prog.py [-h] [--verbosity VERBOSITY]
248 --verbosity VERBOSITY
249 increase output verbosity
250 $ python prog.py --verbosity
251 usage: prog.py [-h] [--verbosity VERBOSITY]
252 prog.py: error: argument --verbosity: expected one argument
256 * The program is written so as to display something when ``--verbosity`` is
261 used, the relevant variable, in this case :attr:`args.verbosity`, is
267 * When using the ``--verbosity`` option, one must also specify some value,
270 The above example accepts arbitrary integer values for ``--verbosity``, but for
276 parser.add_argument("--verbose", help="increase output verbosity",
280 print "verbosity turned on"
287 verbosity turned on
296 --verbose increase output verbosity
322 parser.add_argument("-v", "--verbose", help="increase output verbosity",
326 print "verbosity turned on"
333 verbosity turned on
339 -v, --verbose increase output verbosity
354 help="increase output verbosity")
381 multiple verbosity values, and actually get to use them::
387 parser.add_argument("-v", "--verbosity", type=int,
388 help="increase output verbosity")
391 if args.verbosity == 2:
393 elif args.verbosity == 1:
405 usage: prog.py [-h] [-v VERBOSITY] square
406 prog.py: error: argument -v/--verbosity: expected one argument
415 Let's fix it by restricting the values the ``--verbosity`` option can accept::
421 parser.add_argument("-v", "--verbosity", type=int, choices=[0, 1, 2],
422 help="increase output verbosity")
425 if args.verbosity == 2:
427 elif args.verbosity == 1:
438 prog.py: error: argument -v/--verbosity: invalid choice: 3 (choose from 0, 1, 2)
447 -v {0,1,2}, --verbosity {0,1,2}
448 increase output verbosity
453 Now, let's use a different approach of playing with verbosity, which is pretty
455 verbosity argument (check the output of ``python --help``)::
461 parser.add_argument("-v", "--verbosity", action="count",
462 help="increase output verbosity")
465 if args.verbosity == 2:
467 elif args.verbosity == 1:
483 $ python prog.py 4 --verbosity --verbosity
496 -v, --verbosity increase output verbosity
527 parser.add_argument("-v", "--verbosity", action="count",
528 help="increase output verbosity")
533 if args.verbosity >= 2:
535 elif args.verbosity >= 1:
551 if args.verbosity >= 2:
565 parser.add_argument("-v", "--verbosity", action="count", default=0,
566 help="increase output verbosity")
569 if args.verbosity >= 2:
571 elif args.verbosity >= 1:
606 parser.add_argument("-v", "--verbosity", action="count", default=0)
609 if args.verbosity >= 2:
611 elif args.verbosity >= 1:
632 -v, --verbosity
637 Notice that so far we've been using verbosity level to *change* the text
638 that gets displayed. The following example instead uses verbosity level
645 parser.add_argument("-v", "--verbosity", action="count", default=0)
648 if args.verbosity >= 2:
650 if args.verbosity >= 1: