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
d8ad68f3
Commit
d8ad68f3
authored
Mar 26, 2011
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Plain Diff
Merge
parents
9eea9d39
17ace7a0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
5 deletions
+23
-5
Doc/library/argparse.rst
Doc/library/argparse.rst
+16
-5
Lib/test/test_subprocess.py
Lib/test/test_subprocess.py
+1
-0
Misc/ACKS
Misc/ACKS
+1
-0
Misc/NEWS
Misc/NEWS
+5
-0
No files found.
Doc/library/argparse.rst
View file @
d8ad68f3
...
...
@@ -1314,13 +1314,24 @@ of :data:`sys.argv`. This can be accomplished by passing a list of strings to
Namespace(accumulate=<built-in function sum>, integers=[1, 2, 3, 4])
Custom namespaces
^^^^^^^^^^^^^^^^^
The Namespace object
^^^^^^^^^^^^^^^^^^^^
By default, :meth:`parse_args` will return a new object of type :class:`Namespace`
where the necessary attributes have been set. This class is deliberately simple,
just an :class:`object` subclass with a readable string representation. If you
prefer to have dict-like view of the attributes, you can use the standard Python
idiom via :func:`vars`::
>>> parser = argparse.ArgumentParser()
>>> parser.add_argument('--foo')
>>> args = parser.parse_args(['--foo', 'BAR'])
>>> vars(args)
{'foo': 'BAR'}
It may also be useful to have an :class:`ArgumentParser` assign attributes to an
already existing object, rather than the newly-created :class:`Namespace` object
that is normally used. This can be achieved by specifying the ``namespace=``
keyword argument::
already existing object, rather than a new :class:`Namespace` object. This can
be achieved by specifying the ``namespace=`` keyword argument::
>>> class C:
... pass
...
...
Lib/test/test_subprocess.py
View file @
d8ad68f3
...
...
@@ -1226,6 +1226,7 @@ class POSIXProcessTestCase(BaseTestCase):
stdout
=
subprocess
.
PIPE
,
bufsize
=
0
)
f
=
p
.
stdout
self
.
addCleanup
(
f
.
close
)
try
:
self
.
assertEqual
(
f
.
read
(
4
),
b"appl"
)
self
.
assertIn
(
f
,
select
.
select
([
f
],
[],
[],
0.0
)[
0
])
...
...
Misc/ACKS
View file @
d8ad68f3
...
...
@@ -354,6 +354,7 @@ Brian Harring
Larry Hastings
Shane Hathaway
Rycharde Hawkes
Ben Hayden
Jochen Hayek
Christian Heimes
Thomas Heller
...
...
Misc/NEWS
View file @
d8ad68f3
...
...
@@ -53,6 +53,9 @@ Core and Builtins
Library
-------
-
Issue
#
11659
:
Fix
ResourceWarning
in
test_subprocess
introduced
by
#
11459.
Patch
by
Ben
Hayden
.
-
Issue
#
11635
:
Don
't use polling in worker threads and processes launched by
concurrent.futures.
...
...
@@ -157,6 +160,8 @@ Library
-
Issue
#
9348
:
Raise
an
early
error
if
argparse
nargs
and
metavar
don
't match.
- Issue #8982: Improve the documentation for the argparse Namespace object.
Build
-----
...
...
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