我想使用 python dict 来存储变量引用并能够分配这些引用指出的值。
foo = "foo"
d = {'foo' : foo}
d['foo'] = "bar"
foo
// output: 'foo', but I want it to be 'bar'.
我怎样才能做到这一点?
编辑:一些实际的代码。
settings = values["settings"] // This is a dict, such as {"metoder_alphasort" : "on"}
field_map = {"metoder_alphasort" : profile.metoder_alphasort}
for setting in field_map.keys():
if settings.has_key(setting):
if settings[setting] == 'on':
field_map[setting] = True
# field_map[setting] is now True, but profile.metoder_alphasort is False