On Mon, Nov 3, 2008 at 1:57 AM, <[EMAIL PROTECTED]> wrote: > Steven D'Aprano <[EMAIL PROTECTED]> wrote: >> Now you can monkey patch class A if you want. It's probably not a great >> idea to do this in production code, as it will effect class A everywhere. >> > > This is perfect for me. The code in question is basically a protocol > translator... it receives requests over the network, makes some calls, > and returns the result translated back to the original protocol, so there's > a single instance of each A,B, etc. > >> A.p1 = precall(pre)(postcall(post)(A.p1)) > > Is there a way to do this for all callable methods of A? e.g. > > for x in callable_methods(A): > x = precall(pre)(postcall(post)(x))
for name, attr in A.__dict__.iteritems(): if callable(attr): A.__dict__[name] = precall(pre)(postcall(post)(attr)) Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com > > Thanks! > Mark > > -- > Mark Harrison > Pixar Animation Studios > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list