This is Python 2.2+ but it’s a good example. This page has a lot of Python-think on it as well.
Properties: attributes managed by get/set methods Properties are a neat way to implement attributes whose usage resembles attribute access, but whose implementation uses method calls. These are sometimes known as “managed attributes”. In prior Python versions, you could only do this by overriding __getattr__ and __setattr__; but overriding __setattr__ slows down all attribute assignments considerably, and overriding __getattr__ is always a bit tricky to get right. Properties let you do this painlessly, without having to override __getattr__ or __setattr__.
Table of Contents
- Introduction
- Subclassing built-in types
- Built-in types as factory functions
- Introspecting instances of built-in types
- Static methods and class methods
- Properties: attributes defined by get/set methods
- Method resolution order
- Cooperative methods and “super”
- Overriding the __new__ method
- Metaclasses
- Backwards incompatibilities
- References