representation of unbound methods - strange behaviour

Darrell news at dorb.com
Wed Aug 18 16:12:47 EDT 1999


A variation that works.
>>> class A:
...     pass
...
>>> def f(self, x):
...     print x
...
>>> a=A()
>>> a.F=lambda x, self=a:f(self,x)
>>> a.F(55)
55
>>>

--
--Darrell
Stefan Franke <spamfranke at bigfoot.de> wrote in message
news:37bbecf1.100354231 at news.omnilink.de...
> Why does this happen:
>
> Python 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)] on win32
> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> >>> class A: pass
> >>> def f(): pass
> >>> A.f = f
> >>> A.g = f
> >>> A.f
> <unbound method A.f>
> >>> A.g
> <unbound method A.f>
>                 ^^^
>
> This is independent of the assignment order of f and g:
>
> >>> class A: pass
> >>> def f(): pass
> >>> A.g = f        # swapped
> >>> A.f = f        # order
> >>> A.f
> <unbound method A.f>
> >>> A.g
> <unbound method A.f>
>
> Method caching?
> Stefan
>






More information about the Python-list mailing list