Using class data attributes

Craig Findlay craigf at ilid.com.au
Thu Feb 10 15:51:59 EST 2000


Thanks Skip, those methods seem to be exactly what I was looking for.

Craig

Skip Montanaro <skip at mojam.com> wrote:

>
>    Craig> I would like to be able to read and write data attributes as in
>    Craig> Delphi and automatically invoke functions.
>
>Take a look at the special methods __getattr__ and __setattr__.  They should
>provide the hooks you need to accomplish what you want.  For details, check
>the reference manual section on customizing attribute access:
>
>    http://www.python.org/doc/ref/attribute-access.html
>
>__getattr__ is only called if normal attribute lookup
>fails.  If defined, __setattr__ is always called, even if the attribute in
>question already exists.
>
>Skip Montanaro | http://www.mojam.com/
>skip at mojam.com | http://www.musi-cal.com/
>"Languages that change by catering to the tastes of non-users tend not to do
>so well." - Doug Landauer




More information about the Python-list mailing list