Adding attributes stored in a list to a class dynamically.

Brian Munroe brian.e.munroe at gmail.com
Mon Sep 3 11:03:25 EDT 2007


On Sep 3, 6:34 am, Steven D'Aprano <st... at REMOVE-THIS-
cybersource.com.au> wrote:

> The underscore versions are for customizing the lookup process, not for
> dynamically looking up names. If your class needs to do something non-
> standard when you write obj.name, you might need to write methods
> __getattr__ etc.
>

I absolutely understand that much.

>
> In a nutshell: getattr() etc. are for looking up attributes dynamically
> when you don't know the name of the attribute until runtime. __getattr__
> etc. are for looking up attributes when you need to compute the value on
> the fly. (But an easier, less troublesome way of doing that
> is with properties.)
>

If I think about this in the context of a property, which in my newbie
mind gives you the ability to 'override' the standard behavior when
getting, setting or I suppose deleting a specific attribute.  I think
I understand what you meant by 'compute the value on the fly', the
keyword being *compute*?

thanks for taking the time to explain this (over and over, heh!)

-- brian




More information about the Python-list mailing list