Skip to content
Advertisement

Tag: setattr

getattr and setattr on nested subobjects / chained properties?

I have an object (Person) that has multiple subobjects (Pet, Residence) as properties. I want to be able to dynamically set the properties of these subobjects like so: Currently I get the wrong output: {‘pet’: <__main__.Pet object at 0x10c5ec050>, ‘residence’: <__main__.Residence object at 0x10c5ec0d0>, ‘pet.name’: ‘Sparky’, ‘residence.type’: ‘Apartment’} As you can see, instead of setting the name attribute on the

Advertisement