Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions 10 Doc/library/argparse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ The add_argument() method

* type_ - The type to which the command-line argument should be converted.

* choices_ - A container of the allowable values for the argument.
* choices_ - An iterable of the allowable values for the argument.

* required_ - Whether or not the command-line option may be omitted
(optionals only).
Expand Down Expand Up @@ -1076,7 +1076,7 @@ choices
^^^^^^^

Some command-line arguments should be selected from a restricted set of values.
These can be handled by passing a container object as the *choices* keyword
These can be handled by passing an iterable as the *choices* keyword
argument to :meth:`~ArgumentParser.add_argument`. When the command line is
parsed, argument values will be checked, and an error message will be displayed
if the argument was not one of the acceptable values::
Expand All @@ -1090,9 +1090,9 @@ if the argument was not one of the acceptable values::
game.py: error: argument move: invalid choice: 'fire' (choose from 'rock',
'paper', 'scissors')

Note that inclusion in the *choices* container is checked after any type_
Note that inclusion in the *choices* iterable is checked after any type_
conversions have been performed, so the type of the objects in the *choices*
container should match the type_ specified::
iterable should match the type_ specified::

>>> parser = argparse.ArgumentParser(prog='doors.py')
>>> parser.add_argument('door', type=int, choices=range(1, 4))
Expand All @@ -1103,7 +1103,7 @@ container should match the type_ specified::
doors.py: error: argument door: invalid choice: 4 (choose from 1, 2, 3)

Any object that supports the ``in`` operator can be passed as the *choices*
value, so :class:`dict` objects, :class:`set` objects, custom containers,
value, so :class:`dict` objects, :class:`set` objects, custom iterables,
etc. are all supported.


Expand Down
2 changes: 1 addition & 1 deletion 2 Lib/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ class Action(_AttributeHolder):
float, and complex are useful examples of such callables. If None,
str is used.

- choices -- A container of values that should be allowed. If not None,
- choices -- An iterable of values that should be allowed. If not None,
after a command-line argument has been converted to the appropriate
type, an exception will be raised if it is not a member of this
collection.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Changed the wording in the argparse documentation and argparse.py docstring
by removing the usage of the word "container" and replace it with
"iterable".
Morty Proxy This is a proxified and sanitized view of the page, visit original site.