I am trying to assign variables dynamically to a class:
Example:
class P:
def __init__(self, field):
for key, value in self.func(field):
self.key = value
field = {'a' : 1, 'b' : 2}
obj = P(field)
print(obj.a)
print(obj.b)
Here I want to assign attributes dynamically to a object, basically keys of field dict as attribute. but I think it will assign 'key' as attribute to that object. How can we do this?