Newbie again: computing attributes on the fly

Olaf Delgado delgado at Mathematik.Uni-Bielefeld.DE
Wed Jun 16 22:54:50 CEST 1999


On Wed, 16 Jun 1999, Gordon McMillan wrote:

> [Olaf on my very simple getattr hack]:
> 
> > Yes, I definitely want to generalize that. The problem is that that
> > method may be defined in a superclass, so "self.__dict__" won't find
> > it. AFAIK (which may be not be very far), I have to use "hasattr"
> > and/or "getattr", which in turn will call "__getattr__".
> 
> Oh, getattr isn't bad. Wait 'till you try setattr! Anyway, this 
> should demonstrate how to control the recursion:
[...]

Yes, that looks much more civilized than my version. So, I'll have to take
a closer look at all these magic methods.

-- 
   ////         Olaf Delgado Friedrichs, Uni Bielefeld, Mathematik
   Olaf         Postfach 100131                  (room:  V4-109)
   `='          D-33501 Bielefeld, Germany       (phone: +49 521 106-4765)
                           http://www.mathematik.uni-bielefeld.de/~delgado





More information about the Python-list mailing list