Skip to content

Commit eb42ddb

Browse files
Update example to be clear, valid code.
1 parent e84a2cc commit eb42ddb

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

Doc/library/argparse.rst

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -605,18 +605,12 @@ choices (if specified) or subparser names, along with a "maybe you meant"
605605
suggestion if a close match is found. Note that this only applies for arguments
606606
when the choices specified are strings::
607607

608-
>>> parser = argparse.ArgumentParser(description='Process some integers.',
609-
suggest_on_error=True)
610-
>>> parser.add_argument('--action', choices=['sum', 'max'])
611-
>>> parser.add_argument('integers', metavar='N', type=int, nargs='+',
612-
... help='an integer for the accumulator')
613-
>>> parser.parse_args(['--action', 'sumn', 1, 2, 3])
614-
tester.py: error: argument --action: invalid choice: 'sumn', maybe you meant 'sum'? (choose from 'sum', 'max')
615-
616-
You can disable suggestions by setting ``suggest_on_error`` to ``False``::
608+
>>> parser = argparse.ArgumentParser(suggest_on_error=True)
609+
>>> parser.add_argument('--action', choices=['debug', 'dryrun'])
610+
>>> parser.parse_args(['--action', 'debugg'])
611+
error: argument --action: invalid choice: 'debugg', maybe you meant 'debug'? (choose from 'debug', 'dryrun')
617612

618-
>>> parser = argparse.ArgumentParser(description='Process some integers.',
619-
suggest_on_error=False)
613+
You can disable suggestions by setting ``suggest_on_error`` to ``False``.
620614

621615
.. versionadded:: 3.14
622616
.. versionchanged:: 3.15

0 commit comments

Comments
 (0)