Next / Previous / Contents / TCC Help System / NM Tech homepage

26.1.3. Attribute references in old-style classes

The names inside the instance are called attributes. (The methods are technically attributes—attributes that are of type function.) There are three operations on attributes: get, set, and delete.

In addition to ordinary attributes and methods, your class can accept references to names that do not exist in the instance or class namespace. You can define special methods that will be called when some statement tries to get, set, or delete an attribute that isn't found in the instance's .__dict__. See Section 26.3.14, “__getattr__(): Handle a reference to an unknown attribute”, Section 26.3.21, “__setattr__(): Intercept all attribute changes”, and Section 26.3.9, “__delattr__(): Delete an attribute”.

If all else fails—if an attribute is not found in the instance's namespace and the class does not provide a special method that handles the attribute reference—Python will raise an AttributeError exception.