New submission from fralau <laur2...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue34496>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to