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
Tag: setattr
Python: inconsistence in the way you define the function __setattr__?
Consider this code: I would expect the same output. However, with CPython 2.5, 2.6 (similarly in 3.2) I get: With PyPy 1.5.0, I get the expected output: Which is the “right” output? (Or what should be the output according to the Python documentation?) Here is the bug report for CPython. Answer I suspect it has to do with a lookup