On Fri, Sep 30, 2011 at 3:08 AM, Laurent Claessens <moky.m...@gmail.com> wrote: > class wraper(object): > def __init__(self,fun): > globals()[fun]=self.replacement > def replacement(*args): > print "I'm replaced" > > foo() > X=wraper(foo) > foo() > > I was hoping that globals()[foo] would be replaced by my X.replacement and > thus the second call to foo() was expected to print "I'm replaced".
Actually, I've just realized what your problem might be. Try: X = wraper("foo") You're indexing globals() with the actual function object, but you want to index it with the function _name_. I do think that the decorator technique will be a lot cleaner, though. ChrisA -- http://mail.python.org/mailman/listinfo/python-list