[Compiler-sig] __getattr__ inflexibility

John Max Skaller skaller@maxtal.com.au
Sat, 01 Apr 2000 11:59:28 +1000


Ludvig Svenonius wrote:
> 
> I was wondering about the __getattr__-built-in method. Currently it is
> called only if the attribute could not be found in the instance dictionary.
> Would it not be more flexible to -always- call it upon referencing an
> attribute

This won't work because _inside_ the getattr method, we cannot
refer to any of the object's attributes, since doing so will
recursively invoke the __getattr__ method.

This would _also_ destroy the __setattr__ case, since it
_relies_ on being able to get the __dict__ attribute of an
instance, in order to store attributes (since __setattr__ IS
always invoked on set operation): you have to write

	self.__dict__['attr'] = value

in a __setattr__ method to store a value.

-- 
John (Max) Skaller, mailto:skaller@maxtal.com.au
10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850
checkout Vyper http://Vyper.sourceforge.net
download Interscript http://Interscript.sourceforge.net