What file is foo in package bar in ?

N

northof40

Hi - I think this is a pretty basic question but it's never worried me
before.

To improve my skills I'm reading the source code of a library written
by someone else.

I've come across a problem doing that.

Commonly a function is called like this:

thepackage.theclass.foo

The problem is that 'theclass' is implemented in a file called
nothingliketheclass.py so finding the implemention of foo is a bit
boring.

Now I can grep for foo and depending on how common the method name is
that helps ... or not but I'm sure there must be a better way.

Given an arbitary package is there some programmatic way to 'ask' what
file the method/function is implemented in ?

thanks

R.
 
N

northof40

Indeed, the inspect module contains several useful functions for the
job, for examplehttp://docs.python.org/library/inspect.html#inspect.getfile

Christian

That's really great thanks - just what I was after.

regards

R.
 
N

Nitebirdz

Indeed, the inspect module contains several useful functions for the
job, for example
http://docs.python.org/library/inspect.html#inspect.getfile

Stupid question from someone who ignores it all: since the OP is reading
code from an existing tree in order to learn from it, wouldn't it make
more sense to use something like Cscope? Assuming it works with Python,
of course. If it doesn't, is there a similar tool that can be used? A
related question too is whether any of these tools actually help in an
object-oriented environment.

http://cscope.sourceforge.net/

http://www.linux.com/archive/feature/114237
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top