Question on class member in python
aleaxit at yahoo.com
Tue Oct 18 10:54:42 CEST 2005
Johnny Lee <johnnyandfiona at hotmail.com> wrote:
> Thanks for your help, maybe I should learn how to turn an attibute into
> a property first.
Easy -- in your class's body, just code:
def getFoo(self): ...
def setFoo(self, value): ...
def delFoo(self): ...
foo = property(getFoo, setFoo, delFoo, 'this is the foo')
Note that if you want subclasses to be able to customize behavior of foo
accesses by simple method overrides, you need to program some "hooks"
(an extra level of indirection, if you will).
More information about the Python-list