representation of unbound methods - strange behaviour

Greg Ewing greg.ewing at compaq.com
Wed Aug 18 19:09:01 EDT 1999


Skip Montanaro wrote:
> 
> I believe it is constructing the method name on-the-fly using the names it
> finds in the class and function.

Yep. A slightly different test reveals
what is going on:

def h():
    pass

class A:
    pass

A.f = h
A.g = h
print A.f
print A.g

Output:

<unbound method A.h>
<unbound method A.h>

Greg




  It's not using the attribute name.
> 
>     >>> class A: pass
>     ...
>     >>> def foo(): pass
>     ...
>     >>> A.f = foo
>     >>> A.g = foo
>     >>> A.f
>     <unbound method A.foo>
>     >>> A.g
>     <unbound method A.foo>
> 
> Skip Montanaro  | http://www.mojam.com/
> skip at mojam.com  | http://www.musi-cal.com/~skip/
> 847-971-7098




More information about the Python-list mailing list