difference between class methods and instance methods

Antoon Pardon apardon at forel.vub.ac.be
Fri Feb 18 09:55:42 EST 2005


Op 2005-02-18, Diez B. Roggisch schreef <deetsNOSPAM at web.de>:
>> This is badly wrong. John was correct.
>> 
>> Bound methods get created whenever you reference a method of an instance.
>> If you are calling the method then the bound method is destroyed as soon
>> as the call returns. You can have as many different bound methods created
>> from the same unbound method and the same instance as you want:
>
> That did escape me so far - interesting. Why is it that way? I'd expect that
> creating a bound method from the class and then storing it in the objects
> dictionary is what happens. 
>

No. What happens is that functions are descriptors. So if you
assign a function to a class attribute any access to this
attribute will call the __get__ method which will create a
bound method if the access was through an instance or an
unbound method if the access was through the class.

-- 
Antoon Pardon



More information about the Python-list mailing list