Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
7b2ac609
Commit
7b2ac609
authored
Dec 02, 2013
by
Eli Bendersky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #19814: Clarify argparse's docs w.r.t prefix matching
parent
7546220f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
3 deletions
+11
-3
Doc/library/argparse.rst
Doc/library/argparse.rst
+11
-3
No files found.
Doc/library/argparse.rst
View file @
7b2ac609
...
...
@@ -1351,12 +1351,14 @@ argument::
>>> parser.parse_args(['--', '-f'])
Namespace(foo='-f', one=None)
.. _prefix-matching:
Argument abbreviations
^^^^^^^^^^^^^^^^^^^^^^
Argument abbreviations
(prefix matching)
^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^
The :meth:`~ArgumentParser.parse_args` method allows long options to be
abbreviated if the abbreviation is unambiguous::
abbreviated to a prefix, if the abbreviation is unambiguous (the prefix matches
a unique option)::
>>> parser = argparse.ArgumentParser(prog='PROG')
>>> parser.add_argument('-bacon')
...
...
@@ -1822,6 +1824,12 @@ the populated namespace and the list of remaining argument strings.
>>> parser.parse_known_args(['--foo', '--badger', 'BAR', 'spam'])
(Namespace(bar='BAR', foo=True), ['--badger', 'spam'])
.. warning::
:ref:`Prefix matching <prefix-matching>` rules apply to
:meth:`parse_known_args`. The parser may consume an option even if it's just
a prefix of one of its known options, instead of leaving it in the remaining
arguments list.
Customizing file parsing
^^^^^^^^^^^^^^^^^^^^^^^^
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment