Using class data attributes

Skip Montanaro skip at mojam.com
Wed Feb 9 22:24:54 EST 2000


    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