Grant Edwards wrote:
On 2005-02-17, Steven Bethard <[EMAIL PROTECTED]> wrote:


py> class C(object):
...     def f(self, *args):
...         print "f:", args
...     def g(self, *args):
...         print "g:", args
...
py> class D(C):
...     pass
...
py> class Wrapper(object):
...     def __init__(self, func):
...         self.func = func
...     def __call__(self, *args):
...         print "wrapped"
...         return self.func(*args)
...
py> for name in ['f', 'g']:
...     wrapper = Wrapper(getattr(C, name))
...     setattr(D, name, new.instancemethod(wrapper, None, D))


Thanks.  The stuff provided by the "new" module is what I was
missing.

No magic in the 'new' module - new.instancemethod is just a synonym for the method type:

 >>> import new, types
 >>> new.instancemethod is types.MethodType
True

Michael

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to