How would you go about editing a dictionary as an object attribute? Right now I have I have a class that looks like this:
class Generic_class(object):
def __init__(self):
self.attr1 = default_dict.copy()
self.attr2 = default_dict.copy()
self.attr3 = default_dict.copy()
self.attr4 = default_dict.copy()
...
I am (trying) to do it this way so that I can access the dictionaries as part of an instance of this class, and there could end up being hundreds of different instances. I would like to be able to access the attributes dynamically because the attribute to be accessed is determined by data that is retrieved by the program at run-time. These dictionaries are also going to be edited possibly hundreds of times so something like
attr_name = 'This is dynamic'
instance_dict = default_dict.copy()
instance_dict['a key'] = 'value'
setattr(x, attr_name, instance_dict)
wont work because I need previous edits to remain. Since I need to access the attributes dynamically I can't use x.y['key] = 'value', but I cant edit the dictionary using setattr() so I am not sure what to do.