properties + types, implementing meta-class desciptors elegantly?

Michele Simionato mis6 at pitt.edu
Sun Jul 20 10:52:46 EDT 2003


"Mike C. Fletcher" <mcfletch at rogers.com> wrote in message news:<mailman.1058629890.30475.python-list at python.org>...
<snip>

As others before me, I am not sure of what you are trying to do
and why you are doing so. I use descriptors in this way:

class o(object):
    class p( object ): # descriptor class
        def __set__( self, client, value, *args, **named ):
            print '__set__', self, client, value, args, named
            self.v=value
        def __get__(self,obj,cls):
            return self.v
    v = p()

s=o()

s.v=3 # v is a p-descriptor

print s.v

# Output:
#__set__ <__main__.p object at 0x4031af8c>
 <__main__.o object at 0x4031c0ac> 3 () {}
#3

Does this code help?


                                     Michele




More information about the Python-list mailing list