Generate keyword arguments programmatically in Python
This is a little helper that can be used in Python 3 to generate a set of dictionaries from a schema that specifies iterators that provide the values of the generated dictionaries.
It will generate one dictionary for every configuration (i.e. Cartesian product) of values specified by iterators in the schema. Non-iterable values are kept fixed. Generators may also be used in the schema (see code snippet).
This is useful for programmatically constructing keyword arguments when experimenting with the parameters of functions, because a dictionary can be unpacked into keyword arguments by using the double star operator (**some_dict
) in the last argument position. For this reason, I call the schema the optionset_schema
.