proposal: accessor methods
Michal Wallace
sabren at manifestation.com
Fri Jul 14 15:00:50 EDT 2000
Hey all,
I was just wondering if anyone else would find this useful:
I think that for a given object, it would be nice to define
specific accessor methods for variables, instead of having
to rely on __getattr__ and __setattr__.
For example, if I have an object like this:
o = Object()
o.x = 5
And I later decide that I want setting x to have some sort
of side effect, I'd like to be able to do this:
class Object:
def __set_x(self, value):
self.y = x * 2
This way I don't have to break code. I know I can already do this with
__setattr__, but it's clunky when I want different attributes to do
different things. In fact, I generally just tell __setattr__ to check
to see whether I've defined __set_x and call that.. And I wondered
if anyone else would want to have this built in.
Anyone?
Cheers,
- Michal
------------------------------------------------------------------------
www.manifestation.com www.sabren.com www.linkwatcher.com www.zike.net
------------------------------------------------------------------------
More information about the Python-list
mailing list