[Zope] Re: [Zope-CMF] Persistent dictionaries
Thomas Olsen
tol@tanghus.dk
Sat, 25 Aug 2001 13:29:00 +0200
On Friday 24 August 2001 23:46, Dieter Maurer wrote:
> > self._attributes = {'value':'','html':'','alignment':''}
>
> From here on "self._attributes" is no longer a PersistentMapping
> but a normal Python dictionary.
> Internal modifications do not trigger the persistence machinery.
> They would, if "_attributes" were still a PersistentMapping....
Doh - didn't think of that...
Anyway - I'm lying on the coach with the flu right now so my brain is even
duller than usual :-) Something I don't quite understand about the python
classes:
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?
--
Regards,
Thomas Olsen
http://www.tanghus.dk