Propert handler question

John Roth newsgroups at jhrothjr.com
Thu Oct 30 21:15:34 EST 2003


<user at domain.invalid> wrote in message
news:e2c8c0a72d718c83d1adfe080f1497a8 at news.teranews.com...
> Is there a way, from within a getter/setter method
> linked to a propert, that I can tell which property
> triggered the method?
>
> This would be great, because I need a great number
> of these properties, each having only slightly different
> actions, which could be triggered correctly if
> I knew the name of the property that was being accessed.

The only thing that occurs to me is looking up the call
stack to find what was being accessed. Somehow, that
seems to be the wrong way to approach the problem,
though.

You might want to look at the __getattr__() and
___setattr() magic methods defined in the Python
Language Reference manual (section 3.3.3 in the
Python 2.2.3 manual set.) These are not the easiest
things in the world to program correctly, (setattr in
particular is prone to loops unless you do everything
exactly right) but they
might be what you need in this case, rather than
a boatload of properties.

John Roth
>
> Thanks,
>
> Toby
>






More information about the Python-list mailing list