Lines Matching refs:verbosity
229 parser.add_argument("--verbosity", help="increase output verbosity")
231 if args.verbosity:
232 print("verbosity turned on")
238 $ python3 prog.py --verbosity 1
239 verbosity turned on
242 usage: prog.py [-h] [--verbosity VERBOSITY]
246 --verbosity VERBOSITY
247 increase output verbosity
248 $ python3 prog.py --verbosity
249 usage: prog.py [-h] [--verbosity VERBOSITY]
250 prog.py: error: argument --verbosity: expected one argument
254 * The program is written so as to display something when ``--verbosity`` is
259 used, the relevant variable, in this case :attr:`args.verbosity`, is
265 * When using the ``--verbosity`` option, one must also specify some value,
268 The above example accepts arbitrary integer values for ``--verbosity``, but for
274 parser.add_argument("--verbose", help="increase output verbosity",
278 print("verbosity turned on")
285 verbosity turned on
294 --verbose increase output verbosity
320 parser.add_argument("-v", "--verbose", help="increase output verbosity",
324 print("verbosity turned on")
331 verbosity turned on
337 -v, --verbose increase output verbosity
352 help="increase output verbosity")
379 multiple verbosity values, and actually get to use them::
385 parser.add_argument("-v", "--verbosity", type=int,
386 help="increase output verbosity")
389 if args.verbosity == 2:
391 elif args.verbosity == 1:
404 prog.py: error: argument -v/--verbosity: expected one argument
413 Let's fix it by restricting the values the ``--verbosity`` option can accept::
419 parser.add_argument("-v", "--verbosity", type=int, choices=[0, 1, 2],
420 help="increase output verbosity")
423 if args.verbosity == 2:
425 elif args.verbosity == 1:
436 prog.py: error: argument -v/--verbosity: invalid choice: 3 (choose from 0, 1, 2)
445 -v {0,1,2}, --verbosity {0,1,2}
446 increase output verbosity
451 Now, let's use a different approach of playing with verbosity, which is pretty
453 verbosity argument (check the output of ``python --help``)::
459 parser.add_argument("-v", "--verbosity", action="count",
460 help="increase output verbosity")
463 if args.verbosity == 2:
465 elif args.verbosity == 1:
481 $ python3 prog.py 4 --verbosity --verbosity
494 -v, --verbosity increase output verbosity
525 parser.add_argument("-v", "--verbosity", action="count",
526 help="increase output verbosity")
531 if args.verbosity >= 2:
533 elif args.verbosity >= 1:
549 if args.verbosity >= 2:
564 parser.add_argument("-v", "--verbosity", action="count", default=0,
565 help="increase output verbosity")
568 if args.verbosity >= 2:
570 elif args.verbosity >= 1:
605 parser.add_argument("-v", "--verbosity", action="count", default=0)
608 if args.verbosity >= 2:
610 elif args.verbosity >= 1:
631 -v, --verbosity
636 Notice that so far we've been using verbosity level to *change* the text
637 that gets displayed. The following example instead uses verbosity level
644 parser.add_argument("-v", "--verbosity", action="count", default=0)
647 if args.verbosity >= 2:
649 if args.verbosity >= 1: