Let's Talk About Lambda Functions!

Jonathan Hogg jonathan at onegoodidea.com
Sat Aug 3 11:20:38 CEST 2002


On 2/8/2002 21:32, in article
mailman.1028320386.2558.python-list at python.org, "Ian Bicking"
<ianb at colorstudy.com> wrote:

> Right now there is no other way (I know of) to make a function into a
> method (though it's easy to fake).  If there were such a way, I imagine
> it would be a function (say, "method"), and you'd create a method by
> calling method(instance, function).

Hmmm. So it would look sort of like:

>>> class Foo: pass
... 
>>> def foo( *args ):
...     print 'foo:', args
... 
>>> import new
>>> bar = new.instancemethod( foo, None, Foo )
>>> bar
<unbound method Foo.foo>
>>> 
>>> f = Foo()
>>> bar = new.instancemethod( foo, f, Foo )
>>> bar
<bound method Foo.foo of <__main__.Foo instance at 0x414328>>
>>> 

;-)

Jonathan




More information about the Python-list mailing list