I would like to create attributes of an object based on a dictionary passed in as an argument. Here is the code. But it does not work as
class Obj(object):
def __init__(self, di):
self.a = 0
self.b = 1
for k in di.keys():
name = 'k' + '_' + 'series'
self.name = None
di = {'c':0,'d':1}
Obj_instance = Obj(di)
print Obj_instance.c_series
I get the following error: 'Obj' object has no attribute 'c'
The code read "name" as a literal, and not as the variable defined.