Properties fun with 2.2

Robin Becker robin at jessikat.fsnet.co.uk
Mon Dec 24 04:27:11 EST 2001


In article <mailman.1009181608.27694.python-list at python.org>, Mike C.
Fletcher <mcfletch at rogers.com> writes
>For a long time I've wanted a way to define properties for Python 
>classes that have all the automated checking you'd expect from 
>properties (in order to automatically create GUIs):
.....
>class SimpleProperty( property ):
>       def __init__( self, name, documentation = "" ):
>               property.__init__( self, self.getValue, self.setValue, 
>self.delValue, 
>documentation )
>               self.name = name
>       def getValue( self, client ):
>               return client.__dict__[ self.name ]
>       def setValue( self, client, value ):
>               client.__dict__[ self.name ] = value
>       def delValue( self, client ):
>               del client.__dict__[ self.name ]
>
>class X( object ):
>       first = SimpleProperty( 'first', 'testing documentation' )
>
.....
very nice. I wondered if this stuff would be easy and it seems it can
be. One of the things I need is a collection of properties ie a property

P

with its own attributes (probably properties themselves) which can be
accessed as

P[0]

ie a thing similar to P, but allowed individual values where these
differ from the aggregate. I wonder whether this is more easily done in
2.2. It's quite hard in 2.1.
-- 
Robin Becker



More information about the Python-list mailing list