lazy arithmetic

Alex Martelli aleax at mac.com
Fri Aug 25 10:50:48 EDT 2006


<pianomaestro at gmail.com> wrote:

> Simon Forman wrote:
> > But that's a function, not a class.  When you assign add to an
> > attribute of Item it "magically" becomes a method of Item:
> 
> Yes, I am looking to understand this magic.
> Sounds like I need to dig into these descriptor thingies (again).
> 
> (sound of brain exploding)..

It's really very simple: Python-coded functions (whether their def is in
a classbody or not) are descriptors (objects with a method named __get__
which binds the first argument); classes (and C-coded functions, etc)
are not descriptors (they have no method named __get__ etc etc).  If you
insist, you can write a custom metaclass with a __get__ so that classes
instantiating it ARE descriptors, for example.


Alex



More information about the Python-list mailing list