getting from code object to class/function

Michael Hudson mwh at python.net
Wed Apr 7 14:22:02 EDT 2004


Skip Montanaro <skip at pobox.com> writes:

> The trace module allows you to print all functions which were called at
> least once during a program's run.  I just checked in a change to also track
> caller/callee relationships and display then at program exit.
> 
> Both types of output suffer from the fact that all the trace function gets
> is the current frame.  From there it can find the code object and then the
> source filename and function name.  There is, however, no direct way back
> from the code object to (for example) the class and method which "own" that
> object.  I didn't see anything obvious in the inspect module that would
> allow me to worm around this problem.

gc.get_referrers?

It's impossible in general, of course, because you can using the 'new'
module construct multiple functions that refer to the same code
object.

Cheers,
mwh

-- 
[1] If you're lost in the woods, just bury some fibre in the ground
    carrying data. Fairly soon a JCB will be along to cut it for you
    - follow the JCB back to civilsation/hitch a lift.
                                               -- Simon Burr, cam.misc



More information about the Python-list mailing list