f(arg1,arg2)Should be as follows
f(**{"arg1":hoge, "arg2":fuga})
Suppose you have the function f
and the formal parameters of f
are arg1
and arg2
.
If you specify only one of them, you can call it like f (arg1 =" hoge ")
or f (arg2 =" fuga ")
.
At this time, I want to dynamically decide whether to specify arg1
or to specify arg2
.
For example, "when you want to stochastically decide whether to call arg1
or arg2
" can be done as follows.
python
import numpy as np
Probabilistic arguments= lambda: "arg1" if np.random.rand()> 0.5 else "arg2"
def f(arg1="(empty)", arg2="(empty)"):
print("arg1 = "+str(arg1)+"\narg2 = "+str(arg2))
f(**{Probabilistic arguments():"fuga"})
#Half chance
#
# arg1 = fuga
# arg2 = (empty)
#
#Is displayed,Another half chance
#
# arg1 = (empty)
# arg2 = fuga
#
#Is displayed
Recommended Posts