reuse validation logic with descriptors

David S. davidschein at alumni.tufts.edu
Tue Mar 1 16:09:43 EST 2005


Steven Bethard <steven.bethard <at> gmail.com> writes:
> 
> P.S.  If you haven't already, you should read 
> http://users.rcn.com/python/download/Descriptor.htm a couple of times. 
> It took me until about the third time I read it to really understand 
> what descriptors were doing.  The big thing to remember is that for an 
> instance b,
>      b.x
> is equivalent to
>      type(b).__dict__['x'].__get__(b, type(b))
> and for a class B,
>      B.x
> is equivalent to
>      B.__dict__['x'].__get__(None, B)
> Note that 'x' is always retrieved from the *type* __dict__, not from the 
> *instance* __dict__.

Steve, and others, thanks for the help.  This and Michael Spencer's reply
at http://article.gmane.org/gmane.comp.python.general/390478 have been very
helpful in getting the descriptor definition clear.  For me, it has taken 
reading http://users.rcn.com/python/download/Descriptor.htm about 4 times 
along with your help to get this straight.

Peace,
David S.




More information about the Python-list mailing list