O'Reilly logo

Mastering Object-oriented Python by Steven Lott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 3. Attribute Access, Properties, and Descriptors

An object is a collection of features, including methods and attributes. The default behavior of the object class involves setting, getting, and deleting named attributes. We often need to modify this behavior to change the attributes available in an object.

This chapter will focus on the following five tiers of attribute access:

  • We'll look at built-in attribute processing, which is the simplest, but least sophisticated option.
  • We'll review the @property decorator. A property extends the concept of an attribute to include the processing defined in method functions.
  • We'll look at how to make use of the lower-level special methods that control attribute access: __getattr__(), __setattr__(), and ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required