Problem with inspect.getfile

E

elventear

Hello,

I am trying to use someone else's module that makes use of
inspect.getsourcelines. The code was not working for me, so I have
been debugging to see why it is not working. I have reduced my problem
to getting the wrong file path in the getfile->return
object.co_filename call.

Basically the path I get is:

"/Users/elventear/Documents/UTMEM/Projects/geotools/parsers/parser.py"

When the correct path should be:

"/Users/elventear/Documents/UTMEM/Projects/packages/geotools/parsers/
parser.py"

Finally my PYTHONPATH contains:

"/Users/elventear/Documents/UTMEM/Projects/packages"

So basically, I am able to resolve correctly the package from withing
Python, I don't know why there is this confusion about the filename
that contains my objects and methods.

Any ideas on how to correct this would be appreciated.

This is under MacOSX 10.4.9, Python 2.5 (Build from Fink).

Thanks!
 
E

elventear

Found the offending code. I was importing between files that were at
the same level of the hierarchy without using absolute references.
Coded worked fine, but inspect didn't. Was this gaffe on my part? Or
was inspect supposed to handle it?

Thanks!
 
G

Gabriel Genellina

Found the offending code. I was importing between files that were at
the same level of the hierarchy without using absolute references.
Coded worked fine, but inspect didn't. Was this gaffe on my part? Or
was inspect supposed to handle it?

Could you provide an example?
 
E

elventear

Could you provide an example?

Simple example

My PYTHONPATH points to /python

I have the following:

/python/packages
__init.py__
/containers
__init.py__
module1.py
module2.py

So basically module2 depends on module1. So within module2.py I was I
was doing "import module1" instead of import
"packages.containers.module1". My code ran ok, but the functions in
the inspect module weren't able to handle it (getfile was the source
of the problem).

Thanks.
 
G

Gabriel Genellina

Simple example

My PYTHONPATH points to /python

I have the following:

/python/packages
__init.py__
/containers
__init.py__
module1.py
module2.py

So basically module2 depends on module1. So within module2.py I was I
was doing "import module1" instead of import
"packages.containers.module1". My code ran ok, but the functions in
the inspect module weren't able to handle it (getfile was the source
of the problem).

I tried it with Python 2.5 on Windows XP and couldn't make it fail.
Perhaps it is specific to the Mac, or perhaps it depends on other details
like __init__.py contents, order of imports, or how specifically you
import things.
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top