I am creating a function that returns the value indicated by a variable. how
y = 1. def f(x): return y
I need this function as a function object to create another object
dist = dist.distribution(f, other_variables)
this works great. But if I want to create several different distribution objects (with different functions f in the sense that y is changing). how
dist = dist.distribution(f, other_variables) y = 2. dist2 = dist.distribution(f, other_variables)
Then, all distribution objects return only the last given value of y. I.e.
dist.f()(1.) >>>> 2. dist2.f()(1.) >>>> 2.
Instead of the expected
dist.f()(1.) >>>> 12. dist2.f()(1.) >>>> 2.
Obviously, the problem is that the function f accesses the variable only when it is called, and not initially.
Is there any way? In the end I want: A function with only one variable (x, although in this case it does nothing, it is needed by others), which returns the y value of the moment the distribution is created. Therefore, in principle, I want this function to be deeply copied when initializing the distribution, in the sense that it will no longer be affected by any change of variables. Is it possible?
source share