wrapping a method function call?

Chris Rebert clp at rebertia.com
Mon Nov 3 05:27:15 EST 2008


On Mon, Nov 3, 2008 at 1:57 AM,  <mh at pixar.com> wrote:
> Steven D'Aprano <steven at remove.this.cybersource.com.au> 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
>



More information about the Python-list mailing list