diff options
author | Andrew Svetlov <andrew.svetlov@gmail.com> | 2012-11-28 17:17:26 (GMT) |
---|---|---|
committer | Andrew Svetlov <andrew.svetlov@gmail.com> | 2012-11-28 17:17:26 (GMT) |
commit | e15cb61ddeb54bf4a5e6099520e5712c72ff15bf (patch) | |
tree | dba70150962bb6f05f2eaa62ec494484d509941c /Doc | |
parent | c2a7fd60e1e1cc86c52d7409b5b8d84ee447a4ae (diff) | |
download | cpython-e15cb61ddeb54bf4a5e6099520e5712c72ff15bf.zip cpython-e15cb61ddeb54bf4a5e6099520e5712c72ff15bf.tar.gz cpython-e15cb61ddeb54bf4a5e6099520e5712c72ff15bf.tar.bz2 |
Issue #11076: document the way to convert argparse.Namespace to a dict.
Initial patch by Virgil Dupras.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/argparse.rst | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index 5273e9b..b10df39 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -1425,6 +1425,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 --------------- |