Functions, callable objects, and bound/unbound methods

Ron Garret rNOSPAMon at flownet.com
Fri Dec 1 12:43:33 EST 2006


In article <1164968507.519962.325820 at j44g2000cwa.googlegroups.com>,
 "Michele Simionato" <michele.simionato at gmail.com> wrote:

> Duncan Booth wrote:
> > Ron Garret <rNOSPAMon at flownet.com> wrote:
> >
> > > I want to say:
> > >
> > > trace(c1.m1)
> > >
> > > and have c1.m1 be replaced with a wrapper that prints debugging info
> > > before actually calling the old value of m1.  The reason I want that
> > > to be an instance of a callable class instead of a function is that I
> > > need a place to store the old value of the method so I can restore it,
> > > and I don't want to start building a global data structure because
> > > that gets horribly ugly, and a callable class is the Right Thing -- if
> > > there's a way to actually make it work.
> > >
> > > Is there?  I tried the obvious things (like making callable inherit
> > > from function, and adding im_func and im_self attribuetes) but they
> > > didn't work.
> >
> > Read "Functions and Methods" in
> > http://users.rcn.com/python/download/Descriptor.htm
> >
> > You need to implement a __get__ method on your class.
> 
> See also
> 
> http://groups.google.com/group/comp.lang.python/browse_frm/thread/d691240a5cfe
> bcdf/93503c5b9c66226e?lnk=gst&q=simionato+subclassing+FunctionType&rnum=1&hl=e
> n#93503c5b9c66226e
> 
> for an example and some discussion.
> 
>      Michele Simionato

Thanks!

rg



More information about the Python-list mailing list