python create object and add attributes to it

Posted by John on Stack Overflow See other posts from Stack Overflow or by John
Published on 2010-05-13T14:34:03Z Indexed on 2010/05/13 14:44 UTC
Read the original article Hit count: 151

Filed under:

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?

Thanks

© Stack Overflow or respective owner

Related posts about python