[issue34496] Argparse library: parse --set type

fralau report at bugs.python.org
Sat Aug 25 02:51:30 EDT 2018


New submission from fralau <laur2035 at yahoo.co.uk>:

With argparse, an common requirement is is that a user may want to pass a series of key/value pairs (a sort of equivalent of **args on the command line). Here is a solution that could be implemented in the standard library with little effort.

This can be done so, e.g.:
    command --set foo=hello bar="hello world" baz=5

With the benefit of experience, this is easy and very intuitive.

This does not require any modification, as the '--set' option can be defined as:  
   nargs='+',
   metavar="KEY=VALUE"

The next step is to parse the resulting list.

See github gist for a trivial implementation: https://gist.github.com/fralau/061a4f6c13251367ef1d9a9a99fb3e8d). 

It might be useful to integrate a helper method to the standard library together with an explanation in the doc on how to do it.

----------
components: Library (Lib)
messages: 324043
nosy: fralau
priority: normal
severity: normal
status: open
title: Argparse library: parse --set type
type: enhancement

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34496>
_______________________________________


More information about the Python-bugs-list mailing list