I understand that in python, variables are not storage locations but instead just a name that points to a value elsewhere. Therefore we cannot do something like:
foo = 1
bar = foo
foo = 2
and expect bar
to be updated to 2.
However I am wondering if we can store the "name" foo in a dict and update where the name points to. I know the following does not work but something along the lines of:
foo = 1
bar = 2
dict_of_var = {
"foo": foo,
"bar": bar,
"baz": baz
}
with open(path, 'r') as f:
f_dict = json.load(f)
for key, val in dict_of_var.items():
val = f_dict[key]
Instead of the manual:
with open(path, 'r') as f:
f_dict = json.load(f)
foo = f_dict["foo"]
bar = f_dict["bar"]
baz = f_dict["baz"]
Is this possible at all, either in this way or some other way?