[Persistence-sig] Naive questions about getting and setting

Guido van Rossum guido@python.org
Mon, 29 Jul 2002 17:06:43 -0400


> 1. Would naive (and rather application specific) questions such as
> these be better posed to comp.lang.python? If so, I would happily
> comply in the future.

I don't know, but given the resounding silence in response to your
email you may have drawn this conclusion yourself... :-)

You may also want to read up on descriptors and other aspects of new
types; I wrote a tutorial:

  http://www.python.org/2.2.1/descrintro.html

> 2. In regard to the persistence API and especially in regard to
> observation, would someone please point out the pitfalls of using
> so-called "setter" and "getter" methods in attribute classes
> themselves, as opposed to __setattribute__ and __getattribute__
> methods in the container classes?

There is no __setattribute__; for historical reasons, there's
__getattr__, __setattr__, and __getattribute__.

If you have a few attributes that need special handling, and the rest
don't, implementing them using descriptors is much preferred, because
it doesn't slow down access to the other attributes.  OTOH, if you
need to trap *all* attributes (like Philip's Observable class),
__getattribute__ and __setattr__ are the only way.

> I am in no way proposing this as a general solution, but if in a
> given situation one wanted to set up a scheme similar to that coded
> below, what would be the major liabilities? Is it simply a matter
> of lack of transparency? Or is there also a serious problem with
> decreased efficiency?

I'm afraid I don't understand what your example code is trying to do.
It seems out of scope for this SIG.

--Guido van Rossum (home page: http://www.python.org/~guido/)