how to monitor method calls

Darrell news at dorb.com
Mon Oct 11 10:03:30 EDT 1999


Check out pdb in the docs and see the "how it works" section.
    sys.settrace(func) sets the global trace function

For the line method name stuff check out the exceptions module.

Also here's some code.
def myDirExcept(howFarBack):
        """
        Get the directory of the module running at "howfarBack "
        in the stack frames
        Unix stores a relative path
        Windows stores an absolute path
        """
        try:
                raise ZeroDivisionError
        except ZeroDivisionError:
                f = sys.exc_info()[2].tb_frame

        for i in range(howFarBack):
                f = f.f_back

        t = f.f_code
        # Try dir(t) for a list of useful stuff
        fname = t.co_filename
        p = string.split(fname, os.sep)
        fname = string.join(p[:-1], os.sep)
#        print "Usr Mydir:",fname, "\n"*5
        return fname



--
--Darrell
<zakons at eccelerate.com> wrote in message news:7tsns3$pjj$1 at nnrp1.deja.com...
> I am looking to do some introspection on running python programs to
> track method calls on objects.
>
> Is there a 'hook' into python to intercept all method calls?
> If so, can someone point me to the right way to introspect which class
> owns the method, the name of the object, etc.
> Any examples out there of this?
>
> Thanks much,
> Stuart Zakon
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
> --
> http://www.python.org/mailman/listinfo/python-list






More information about the Python-list mailing list