[Zope] Re: [Zope-CMF] Persistent dictionaries

Dieter Maurer dieter@handshake.de
Sun, 26 Aug 2001 00:09:50 +0200 (CEST)


Thomas Olsen writes:
 > ....
 > Say you have an instance of a class MyClass with attributes myattr1 and 
 > myattr2; then you change the class definition for MyClass adding myattr3.
 > If attributes are stored in dictionary __dict__ isn't it possible simply to 
 > do:
 > 
 > def __getattr__(self, name): # or maybe __setstate__(self):
 >     if not self.hasattr(name):
 >         # add attribute name
 >         self.__dict__[name] = ""
 > 
 > Shouldn't this add the attribute to the class instance?
Usually, it would not work....
Several reasons:

  1. Your "__getattr__" would define any attribute that is
     not already there. I doubt this is useful...

  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.


Dieter