Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 51292ff

Browse files
committed
Merge issue #11076: document the way to convert argparse.Namespace to a dict.
Initial patch by Virgil Dupras.
2 parents 1fb4758 + e15cb61 commit 51292ff

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

Doc/library/argparse.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,21 @@ be achieved by specifying the ``namespace=`` keyword argument::
14441444
'BAR'
14451445

14461446

1447+
Converting the namespace to a dict
1448+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1449+
1450+
It's possible to convert a namespace to a :class:`dict` by using the built-in
1451+
function :func:`vars` in this fashion::
1452+
1453+
args = parser.parse_args()
1454+
argdict = vars(args)
1455+
1456+
This makes it easy to introspect the namespace or to pass the command-line
1457+
arguments to a function taking a bunch of keyword arguments::
1458+
1459+
somefunction(**vars(parser.parse_args()))
1460+
1461+
14471462
Other utilities
14481463
---------------
14491464

0 commit comments

Comments
 (0)