durusmail: quixote-users: Re: Accessor methods and ZODB
Accessor methods and ZODB
2004-03-25
2004-03-25
2004-03-26
2004-03-26
2004-03-26
Re: Accessor methods and ZODB
2004-03-26
Re: Accessor methods and ZODB
Graham Fawcett
2004-03-26
Daniel Potter (Ars Analytica) wrote:

> One uses .set_x(y) to avoid typos which create a new
> variable instead of doing the assignement intended.
>
> In the case of Dulci (in particular the places that
> use ZODB) the use the .set_x(y) formalism to allows
> one to do some type checking.
>
> My guess is that the .get_x() formalism is used simply
> to match the .set_x(y) formalism.

As of ZODB 3.3 (which I believe is still in alpha), there is support for
objects of new-style classes, which means that you should also be able to use
the 'properties' features introduced in Python 2.2. With properties, you can
write 'get_foo()' and 'set_foo()' methods, and wrap them in a property,
allowing you to simply write 'x = obj.foo' and 'obj.foo = f' in your user code.

Of course, you'd have to store your real 'foo' attribute under a different
attribute name, e.g. _foo, since 'foo' will be in use as the name of the
property.

Untried, of course, ;-), but there's no reason it shouldn't work.

Jeremy Hylton's announcement re: ZODB 3.3a2:
http://www.python.org/~jeremy/weblog/040106.html

Brief intro to properties from GvR:
http://www.python.org/2.2/descrintro.html#property

-- Graham



reply