473,394 Members | 1,658 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

getting from code object to class/function

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.

A not perfect solution would seem to be: if the first element of the code's
co_varnames attribute is "self" and the object in question is an instance,
work back to the class and grab the class name (which is only available
indirectly via str()), then use it to embellish the function name found in
the code object.

I'm open to other suggestions.

Thx,

Skip

Jul 18 '05 #1
1 1328
Skip Montanaro <sk**@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
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Fernando Rodriguez | last post by:
Hi, I need to traverse the methods defined in a class and its superclasses. This is the code I'm using: # An instance of class B should be able to check all the methods defined in B #and A,...
2
by: Eyal | last post by:
Hey, I would appriciate if anyone can help on this one: I have a java object/inteface having a method with a boolean parameter. As I'm trying to call this method from a javascript it fails on...
6
by: Martin | last post by:
I'd like to be able to get the name of an object instance from within a call to a method of that same object. Is this at all possible? The example below works by passing in the name of the object...
41
by: Jim | last post by:
Hi guys, I have an object which represents an "item" in a CMS "component" where an "item" in the most basic form just a field, and a "component" is effectively a table. "item" objects can be...
4
by: My Pet Programmer | last post by:
Ok guys, I'm really looking for someone to tell me how bad a hack this is, and if I'm close to where I should be with it. The basic situation is that I have a class which creates a basic...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.