Summary
In this chapter, we looked at several ways to work with an object's attributes. We can use the built-in features of the object class to get and set attribute values simply and effectively. We can use @property to create attribute-like methods.
If we want more sophistication, we can tweak the underlying special method implementations for __getattr__(), __setattr__(), __delattr__(), or __getattribute__(). These allow us very fine-grained control over attribute behaviors. We walk a fine line when we touch these methods because we can make fundamental (and confusing) changes to Python's behavior.
Internally, Python uses descriptors to implement features such as class methods, static methods, and properties. Many of the really good use ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access