Attaching functions to objects as methods
John Machin
sjmachin at lexicon.net
Fri Jul 7 21:39:57 EDT 2006
On 8/07/2006 11:01 AM, tac-tics wrote:
> Experimenting, I found that
>
>>>> x.fun = lambda: fun(x)
>
> works as well. Any comments on this way?
>
Appears to work. Less typing for a no-argument method, but you need to
specify the argument list *twice* compared with *zero* times with the
types.MethodType way of doing it.
>>> x=K()
>>> x.metho = lambda(a): own(x, a)
>>> x.metho('abcde')
own
>>> x.ozz
'abcde'
>>>
More information about the Python-list
mailing list