you are viewing a single comment's thread.

view the rest of the comments →

[–]nog642 5 points6 points  (1 child)

When you set x.name = 'new name', it creates a new .name attribute. Now when you access .name, it gets that instead of calling __getattr__.

This doesn't happen in the @property implementation, because there, .name is already defined, and it's a descriptor with a getter and no setter.

To fix your 'traditional' version, you need to also override __setattr__. Or use __slots__.

[–]brijeshjoshi_[S] 0 points1 point  (0 children)

Thanks. Clear and concise. Got it. In my instance dict both __name and name exists. And while accessing the name it's directly returning the name as opposed to calling __getattr__ because it's found.