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:
482 $ python3 prog.py 4 --verbosity --verbosity
495 -v, --verbosity increase output verbosity
526 parser.add_argument("-v", "--verbosity", action="count",
527 help="increase output verbosity")
532 if args.verbosity >= 2:
534 elif args.verbosity >= 1:
550 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: