Hi,
I want to create a dynamic object (inside another object) in python and then add attributes to it.
I tried:
obj = someobject
obj.a = object()
setattr(obj.a, 'somefield', 'somevalue')
but this didn't work.
Any ideas?
edit:
I am setting the attributes from a for loop which loops through a list of values. e.g.
params = ['attr1', 'attr2', 'attr3']
obj = someobject
obj.a = object()
for p in params:
obj.a.p # where p comes from for loop variable
so in the above example I would get obj.a.attr1, obj.a.attr2, obj.a.attr3.
I used the setattr function because I didn't know how to do obj.a.NAME FROM FOR LOOP
How would I set the attribute based on the value of p in the example above?
Thanks