John Machin wrote:
> Injecting a "private" method into a particular instance is not much more
> complicated:
>
> >>> def own(self, arg):
> ...print "own"
> ...self.ozz = arg
> ...
> >>> p = K()
> >>> import types
> >>> p.metho = types.MethodType(own, p)
> >>> p.metho("plugh")
> own
>
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
Experimenting, I found that
>>> x.fun = lambda: fun(x)
works as well. Any comments on this way?
--
http://mail.python.org/mailman/listinfo/python-list
On 8/07/2006 9:29 AM, tac-tics wrote:
> Python is a crazy language when it comes to object versatility. I know
> I can do:
>
class test:
> ...def __init__(self):
> ... pass
x = test()
def fun():
> ... print "fun"
x.fun = fun
x.fun()
> fun
>
> However, expe
> Functions are descriptors[1], and their __get__ method is used to bind
> them to a particular instance::
Thank you muchly.
--
http://mail.python.org/mailman/listinfo/python-list
tac-tics wrote:
> Python is a crazy language when it comes to object versatility. I know
> I can do:
>
class test:
> ...def __init__(self):
> ... pass
x = test()
def fun():
> ... print "fun"
x.fun = fun
x.fun()
> fun
>
> However, experimenting shows that t
Python is a crazy language when it comes to object versatility. I know
I can do:
>>> class test:
...def __init__(self):
... pass
>>> x = test()
>>> def fun():
... print "fun"
>>> x.fun = fun
>>> x.fun()
fun
>>>
However, experimenting shows that these attached functions are not
bou