Wrapping method calls with metaclasses

Lawrence Oluyede raims at dot.com
Tue Dec 6 18:27:10 CET 2005


I've never used metaclasses in real life before and while searching through
the online Cookbook I found this gorgeous example:

"Wrapping method calls (meta-class example)"
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/198078

What I want to do in my app is to log all method calls and seems that the
metaclass example above do this fine but it fails when it's needed to
instantiate the class I'm in in a method. So if I do:

class Test(object):
    __metaclass__ = LogTheMethods
    def foo(self):
      return Test()

this generate a Runtime Error cause recursion never stops :(
Any hint to enhance the example?


-- 
Lawrence - http://www.oluyede.org/blog
"Anyone can freely use whatever he wants but the light at the end
of the tunnel for most of his problems is Python"



More information about the Python-list mailing list