Another of those "is" issues.

Scott David Daniels Scott.Daniels at Acm.Org
Fri Mar 20 19:47:53 CET 2009

Emanuele D'Arrigo wrote:
> Hi everybody, ...
>>>> f = aFunction
>>>> f is aFunction
> True   <--- Ok, this seems reasonable. Nevertheless, I suspect I
>             shouldn't quite rely on it.
Actually, that's fine, you are simply comparing a pair of references

>>>> class MyClass(object):
> ...     def myMethod(self):
> ...         pass
>>>> c = MyClass()
>>>> m = c.myMethod
>>>> m is c.myMethod
> False  <--- What? Why is that?

Method access binds the instance in dynamically.

Comparing             m is c.myMethod
is like comparing     m is partial(MyClass.method, c)

--Scott David Daniels
Scott.Daniels at Acm.Org

More information about the Python-list mailing list