passing methods/functions

Quinn Dunkan quinn at groat.ugcs.caltech.edu
Mon May 8 15:34:03 EDT 2000


On Sun, 07 May 2000 19:02:37 GMT, Courageous <jkraska1 at san.rr.com> wrote:
>
>> A "bound method" basically keeps a pair of references - to the method
>> and the instance:
>
>Is there a way to get lambda expressions to produce bound methods?
>If not, mlambda would be a nice addition to the language.

I'm not sure I understand what you mean, it sounds like you want something
like "singleton methods"?  In any case, you could perhaps simulate that with
default args:

>>> class A:
...     def __init__(self):
...         self.val = 0
...     def meth(self):
...         return self.val
...
>>> a = A()
>>> a.meth2 = lambda self=a: self.val + 1
>>> a.meth2()
1



More information about the Python-list mailing list