Thomas Olsen writes:
On Sunday 26 August 2001 00:09, Dieter Maurer wrote:
Say you have an instance of a class MyClass with attributes myattr1 and myattr2; then you change the class definition for MyClass adding myattr3.
Thomas Olsen writes: 2. Python calls "__getattr__" only the normal lookup was not successful. The normal lookup will find the class attribute "myattr3", "__getattr__" would not be called.
But if the object was instantiated before adding myattr3 to the class definition the objects __dict__ wouldn't contain it and you would get an AttributeError when trying to access it if you didn't implement __getattr__? The class dict is searched dynamically. Attributes are not copied at instance creation time. It is not necessary to implement "__getattr__" for this.
Dieter