summaryrefslogtreecommitdiffstats
path: root/Doc/library/argparse.rst
diff options
context:
space:
mode:
authorAndrew Svetlov <andrew.svetlov@gmail.com>2012-11-28 17:18:09 (GMT)
committerAndrew Svetlov <andrew.svetlov@gmail.com>2012-11-28 17:18:09 (GMT)
commit51292fff3f61c20af9a4d684414000db797f1d4a (patch)
tree896c2f5bbef5f91c60273599f993eaf743302c06 /Doc/library/argparse.rst
parent1fb47587a147f4f0a8a0ce8c82c27ed8f566b888 (diff)
parente15cb61ddeb54bf4a5e6099520e5712c72ff15bf (diff)
downloadcpython-51292fff3f61c20af9a4d684414000db797f1d4a.zip
cpython-51292fff3f61c20af9a4d684414000db797f1d4a.tar.gz
cpython-51292fff3f61c20af9a4d684414000db797f1d4a.tar.bz2
Merge issue #11076: document the way to convert argparse.Namespace to a dict.
Initial patch by Virgil Dupras.
Diffstat (limited to 'Doc/library/argparse.rst')
-rw-r--r--Doc/library/argparse.rst15
1 files changed, 15 insertions, 0 deletions
diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst
index 9f6a1ea..ab84c89 100644
--- a/Doc/library/argparse.rst
+++ b/Doc/library/argparse.rst
@@ -1444,6 +1444,21 @@ be achieved by specifying the ``namespace=`` keyword argument::
'BAR'
+Converting the namespace to a dict
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+It's possible to convert a namespace to a :class:`dict` by using the built-in
+function :func:`vars` in this fashion::
+
+ args = parser.parse_args()
+ argdict = vars(args)
+
+This makes it easy to introspect the namespace or to pass the command-line
+arguments to a function taking a bunch of keyword arguments::
+
+ somefunction(**vars(parser.parse_args()))
+
+
Other utilities
---------------