I want to assign a class attribute via a string object – but how?
Example:
class test(object): pass a = test() test.value = 5 a.value # -> 5 test.__dict__['value'] # -> 5 # BUT: attr_name = 'next_value' test.__dict__[attr_name] = 10 # -> 'dictproxy' object does not support item assignment
There is a builtin function for this:
Reference: http://docs.python.org/library/functions.html#setattr
Example: