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
c9007081
Commit
c9007081
authored
Jan 09, 2011
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Wrap some long examples and signatures.
parent
efb6902c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
7 deletions
+14
-7
Doc/library/argparse.rst
Doc/library/argparse.rst
+14
-7
No files found.
Doc/library/argparse.rst
View file @
c9007081
...
...
@@ -120,7 +120,9 @@ command-line args from :data:`sys.argv`.
ArgumentParser objects
----------------------
.. class:: ArgumentParser([description], [epilog], [prog], [usage], [add_help], [argument_default], [parents], [prefix_chars], [conflict_handler], [formatter_class])
.. class:: ArgumentParser([description], [epilog], [prog], [usage], [add_help], \
[argument_default], [parents], [prefix_chars], \
[conflict_handler], [formatter_class])
Create a new :class:`ArgumentParser` object. Each parameter has its own more
detailed description below, but in short they are:
...
...
@@ -563,7 +565,9 @@ your usage messages.
The add_argument() method
-------------------------
.. method:: ArgumentParser.add_argument(name or flags..., [action], [nargs], [const], [default], [type], [choices], [required], [help], [metavar], [dest])
.. method:: ArgumentParser.add_argument(name or flags..., [action], [nargs], \
[const], [default], [type], [choices], [required], \
[help], [metavar], [dest])
Define how a single command line argument should be parsed. Each parameter
has its own more detailed description below, but in short they are:
...
...
@@ -777,9 +781,11 @@ values are:
>>> parser.add_argument('outfile', nargs='?', type=argparse.FileType('w'),
... default=sys.stdout)
>>> parser.parse_args(['input.txt', 'output.txt'])
Namespace(infile=<open file 'input.txt', mode 'r' at 0x...>, outfile=<open file 'output.txt', mode 'w' at 0x...>)
Namespace(infile=<open file 'input.txt', mode 'r' at 0x...>,
outfile=<open file 'output.txt', mode 'w' at 0x...>)
>>> parser.parse_args([])
Namespace(infile=<open file '<stdin>', mode 'r' at 0x...>, outfile=<open file '<stdout>', mode 'w' at 0x...>)
Namespace(infile=<open file '<stdin>', mode 'r' at 0x...>,
outfile=<open file '<stdout>', mode 'w' at 0x...>)
* ``'*'``. All command-line args present are gathered into a list. Note that
it generally doesn't make much sense to have more than one positional argument
...
...
@@ -1753,11 +1759,12 @@ backwards compatibility.
A partial upgrade path from optparse to argparse:
* Replace all ``add_option()`` calls with :meth:`ArgumentParser.add_argument` calls.
* Replace all ``add_option()`` calls with :meth:`ArgumentParser.add_argument`
calls.
* Replace ``options, args = parser.parse_args()`` with ``args =
parser.parse_args()`` and add additional :meth:`ArgumentParser.add_argument`
calls for the
positional arguments.
parser.parse_args()`` and add additional :meth:`ArgumentParser.add_argument`
calls for the
positional arguments.
* Replace callback actions and the ``callback_*`` keyword arguments with
``type`` or ``action`` arguments.
...
...
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