I want to setup an environment in a Jupyter notebook where parameters are stored in a dictionary parValue and where you can change values of one or several parameters with a function par(), while letting the actual dictionary parValue stay "under the hood", i.e not directly used by the user. The following setup script` partest.py does that:
global parValue; parValue = {}
parValue['a'] = 1
parValue['b'] = 2
def par(parValue=parValue, *x, **x_kwarg):
x_kwarg.update(*x)
x_temp = {}
for key in x_kwarg.keys():
if key in parValue.keys():
x_temp.update({key: x_kwarg[key]})
else:
print('Error')
parValue.update(x_temp)
In a Jupyter notebook I can then write:
run -i partest.py
# Change a single parameter
par(a=1.5)
# Change two parameters
par(a=1.1, b=2.1)
However, I also want to be able to change the entire dictionary parValue to, say, parValue2 with a similar command:
parValue2 = {'a':1.2, 'b':2.2}
par(parValue2)
But that does not work. I do not get any error message, but parValue2 does not propagate to parValue.
How could the function par() above be modified to handle this?
I know that in the notebook I could have the command:
parValue.update(parValue2)
but I want the dictionary parValue to be "hidden" for the person who uses the notebook.
parValueparameter at all?