Find out where a class is used throughout a program.

Steven D'Aprano steve at pearwood.info
Wed Sep 4 22:16:07 EDT 2013


On Wed, 04 Sep 2013 09:32:28 -0700, Azureaus wrote:

> To try and make this question as general as possible - is there a way of
> finding out / visualising where a particular class is called/used
> throughout a program? I need to find out the way in which these classes
> are being used and their typical input (and where the output from these
> are going) so I can have a play around and really figure out how it
> works. Without a run method to call, or an idea of expected input/output
> it's difficult. Also without some sort of trace it's difficult.


Does the class not come with any documentation?

Start the Python interactive interpreter, and then enter these two lines:

import name_of_module
help(name_of_module.MyClassName)



where, of course, you replace name_of_module with the actual name of the 
module, and MyClassName with the actual name of the class.


If that doesn't solve your problem, you can use the searching tools of 
your choice to search for uses of the class. Open some source file in 
your editor and search for "MyClassName" and see what comes up. Repeat 
for any other source files you care about.

On a Linux or Mac system, you can use external tools. At the shell (not 
the Python shell, the operating system's shell) enter:

cd directory/where/my/source/code/lives
grep *.py MyClassName


or similar. Windows may have a similar tool, but I don't know what it is.



-- 
Steven



More information about the Python-list mailing list