How can I built in a trace ability to python calls? -
How can I built in a trace ability to python calls? -
suppose have python code, e.g. class defined somewhere, which cannot modified
class myclass(object): def __init__(self, arg1, arg2): do_something... def foo(self): do_something
now want add together trace capability, e.g. mechanism outside traces each , every method phone call above class. want able print out when e.g, __init__
has been called, or foo
or __del__
method of myclass
.
is possible do, , how done best?
create proxy class wraps original class , delegates work after printing trace:
class myclassproxy(object): def __init__(*args, **kwds): print 'initializing' self.o = myclass(*args, **kwds) def foo(self): print 'fooing' homecoming self.o.foo()
python python-2.7 trace
Comments
Post a Comment