Converting an arbitrary list of key-value pairs from the command-line into a Python dictionary
You want to create a series of key-value pairs from the command line, using the argparse library, e.g.:
command par1 par2 --set foo=hello bar="hello world" baz=5
This is typically useful when you want to clearly distinguish":
- Ordinary arguments for the command-line utility itself (output, input, format, etc.) from
- A set of key-value pairs you want to pass to the python application. This is especially valid when you do not want that set of values to be predetermined, as this can save a lot of code.