difference between class methods and instance methods
Duncan Booth
duncan.booth at invalid.invalid
Thu Feb 17 12:11:33 EST 2005
John wrote:
>> Note that it doesn't matter whether you call instance.foo(2)
>> directly, or bind instance.foo to a variable first. Either will
>> create a *new* bound method object, and the correct instance is used
>> for the call.
>
> Za! What do you mean, "create a new bound method object"? I *already*
> created that method when I def'd it inside the 'class Demo' statement,
> no?
>
The def statement creates a function.
Accessing the method through the class creates a brand new unbound method
from the function. Every access of the method through the class creates a
separate unbound method.
Accessing the method through the instance creates a brand new bound method.
Every such access creates a separate bound method.
>
> ... hmm... bound methods get created each time you make
> a call to an instance method via an instance of the given class?
>
you've got it.
More information about the Python-list
mailing list