I have a python program (or function) and I want to call it with different values for its parameters.
Suppose the function is:
myfunc(x = 0,y = 0,z =0, w=0, ...):
I use a command line like this to set parameters:
run x=2#3#4--y=1#2--z=5
It shows values for x,y, and z (The number of parameters isn't fixed, many could have default values and I want to set arbitrary set of them). I want to call the function with all combinations such as x=2, y=1, z=5. For this example there are 6 combinations.
I tried to write it with a loop but i think it must be written recursively, because in loop I don't know when to set and unset variables for a next run.
all_vars = var.split("--")
cont = True
while cont:
ii = 0
for _var in all_vars:
_var_name,_var_item_list = _var.split("=")
_var_item_list = _var_item_list.split("#")
cont = False
for var_item in _var_item_list:
if not _var_name in args or args[_var_name] != var_item
args[_var_name] = var_item
_output_name += "_" + _var_name + "_" + str(var_item)
cont = True
ii += 1
break
else:
continue
if cont and ii == len(all_vars):
ctx.invoke(run, **args) # calling the function