Re: Question on class member in python
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: Question on class member in python

From: Aahz <aahz@pythoncraft.com>
Date: Tue Oct 18 2005 - 21:59:28 CEST

In article <1h4mjg9.1n5khr7pjy1zN%aleaxit@yahoo.com>,
Alex Martelli <aleaxit@yahoo.com> wrote:
>Johnny Lee <johnnyandfiona@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).

Or wait for

    foo = property('getFoo', 'setFoo')

(Currently proposed by Guido on python-dev)

-- 
Aahz (aahz@pythoncraft.com)           <*>         http://www.pythoncraft.com/
"If you think it's expensive to hire a professional to do the job, wait
until you hire an amateur."  --Red Adair
Received on Mon Oct 24 01:45:13 2005