summaryrefslogtreecommitdiffstats
path: root/Doc/library/argparse.rst
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-03-26 20:16:07 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2011-03-26 20:16:07 (GMT)
commitd8ad68f34c23645c1a1dfadd63470b3851ba5bea (patch)
tree425fbea238f8f36869c6096b3633239387f718d7 /Doc/library/argparse.rst
parent9eea9d39c1bf0d01ef5ee00cc0c1bedde9c635a7 (diff)
parent17ace7a07c4fe23afc25383799aa184dbb707f14 (diff)
downloadcpython-d8ad68f34c23645c1a1dfadd63470b3851ba5bea.zip
cpython-d8ad68f34c23645c1a1dfadd63470b3851ba5bea.tar.gz
cpython-d8ad68f34c23645c1a1dfadd63470b3851ba5bea.tar.bz2
Merge
Diffstat (limited to 'Doc/library/argparse.rst')
-rw-r--r--Doc/library/argparse.rst21
1 files changed, 16 insertions, 5 deletions
diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst
index 8bd3ca5..102b3e9 100644
--- a/Doc/library/argparse.rst
+++ b/Doc/library/argparse.rst
@@ -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