[Zope] Re: [Zope-CMF] Persistent dictionaries
Tres Seaver
tseaver@palladion.com
Fri, 24 Aug 2001 12:35:12 -0400 (EDT)
On Fri, 24 Aug 2001, Thomas Olsen wrote:
> On Friday 24 August 2001 13:53, Tres Seaver wrote:
>
> > > _attributes = PersistentMapping()
> >
> > Note that this spelling make '_attributes' a "shared instance
> > attribute" (all instances of the class, or ony class derived
> > from it, will share the mapping.
>
> Oops - that certainly wasn't intentionally... I'm still very
> much of a Python newbie. Must have mixed it up with something
> else. I thought it was the notation for a pseudo private
> attribute. Need to pickup "Programming Python" a bit more often
> :-)
My mistake: I said "spelling" when I meant to say "location of
the attribute assignment" (i.e., at class scope, rather than
bound to 'self'); the leading underscore *does* signal (by
convention in Python, and by check in Zope) "privateness" of the
attribute.
> > Normally, I would expect to
> > see the '_attibutes' assigned either in the initializer::
> >
> > def __init__( self ):
> >
> > self._attributes = PersistentMapping()
> >
> > or else "lazily"::
> >
> > _attributes = None;
> >
> > def __getattr__( self, name ):
> >
> > if self._attributes is None:
> > self._attributes = PersistentMapping()
> >
> > if self._attributes.has_key( name ): #...
>
> The lazy approach looks very sensible.
>
> > >
> > > It works great - until the object gets unloaded from the memory :-(
> > >
> > > What am I doing wrong?
> >
> > Note as well that plaing with '__getattr__' in the presence of
> > the acquisition machinery could be classifieds as Deep Voodoo (tm);
>
> :-) Are there any serious pitfalls I ought to know about?
I could tell you, but then you'd have to scrape your brains off
of the ceiling. :) Seriously, acquisition itself relies on
hooking '__getattr__' in fairly fiendish ways; I am reluctant to
try any technique which might fight with it.
Tres.
--
===============================================================
Tres Seaver tseaver@zope.com
Zope Corporation "Zope Dealers" http://www.zope.com