Alexander Staubo wrote:
Is it possible to have persistent objects with attributes
that are only
persistent in memory?
Yes, but it takes some work and the mechanism need to be formalized. Would you want to specify this on a per-class or per-instance basis?
That would be great. Personally? Per class. But wouldn't it be possible to do something like self._p_nodeactivate = 1 or was that being too naive? :) [snip]
def my_method(self): self._v_foo = (hasattr(self, '_v_foo') and self._v_foo) or '<default>'
This is one way.
...ad tedium if you have lots of methods.
Yup.
Does the persistence engine support an "onload" mechanism which you can override to know when your instance has been loaded and needs to initialize itself?
Yup, it's called __setstate__. __setstate__ is called when the object state is loaded. You can overload __setstate__ and initialize any volitile variables when you load your state:
class C: def __setstate__(self, state): C.inheritedAttribute('__setstate__')(self, state) self._v_spam=.....
Just what I was looking for. Yum, thanks. For future reference and posterity's sake, is this stuff documented anywhere except in the UML documentation?
Jim
-- Jim Fulton mailto:jim@digicool.com Python Powered! Technical Director (888) 344-4332 http://www.python.org Digital Creations http://www.digicool.com http://www.zope.org
-- Alexander Staubo http://www.mop.no/~alex/ "Give me an underground laboratory, half a dozen atom smashers and a beautiful girl in a diaphanous veil waiting to be turned into a chimpanzee, and I care not who writes the nation's laws." --S. J. Perelman