difference between class methods and instance methods

John john_sips_teaz at yahooz.com
Thu Feb 17 13:37:01 EST 2005


Duncan Booth wrote:
> [snip]
> 
> 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:
> 
> 
>inst = C()
>f1 = inst.foo
>f2 = inst.foo
>f1, f2
> 
> (<bound method C.foo of <__main__.C instance at 0x00B03F58>>, <bound method 
> C.foo of <__main__.C instance at 0x00B03F58>>)
> 

I just wanted to interject, although those two hex
numbers in the above line are the same, calling
id() on f1 and f2 produces two *different* numbers,
which agrees with the point you made.

>>>>f1 is f2
> 
> False
> 
>>>>f1 is inst.foo
> 
> False
> 
> 
> Every reference to inst.foo is a new bound method.



-- 
--- remove zees if replying via email ---



More information about the Python-list mailing list