Index: Doc/library/argparse.rst =================================================================== --- Doc/library/argparse.rst (revision 88318) +++ Doc/library/argparse.rst (working copy) @@ -1313,7 +1313,20 @@ >>> parser.parse_args('1 2 3 4 --sum'.split()) Namespace(accumulate=, integers=[1, 2, 3, 4]) +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())) + Custom namespaces ^^^^^^^^^^^^^^^^^