diff options
author | Andrew Svetlov <andrew.svetlov@gmail.com> | 2012-11-28 19:18:25 +0200 |
---|---|---|
committer | Andrew Svetlov <andrew.svetlov@gmail.com> | 2012-11-28 19:18:25 +0200 |
commit | adec76a28fddbccf06ea863320382ece10517619 (patch) | |
tree | df293831f5639fec668e6a0b9f496ffb467945fb | |
parent | a6dfe542d7d88dc3a9a96156211e54974494f3e9 (diff) | |
parent | 51292fff3f61c20af9a4d684414000db797f1d4a (diff) | |
download | cpython-git-adec76a28fddbccf06ea863320382ece10517619.tar.gz |
Merge issue #11076: document the way to convert argparse.Namespace to a dict.
Initial patch by Virgil Dupras.
-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 9f6a1eaf9d..ab84c89283 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 --------------- |