By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,550 Members | 1,189 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,550 IT Pros & Developers. It's quick & easy.

Problem with inspect.getfile

P: n/a
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!

May 1 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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!

On May 1, 12:48 pm, elventear <elvent...@gmail.comwrote:
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!

May 2 '07 #2

P: n/a
En Wed, 02 May 2007 02:53:55 -0300, elventear <el*******@gmail.com>
escribió:
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?

--
Gabriel Genellina
May 2 '07 #3

P: n/a
On May 2, 1:12 am, "Gabriel Genellina" <gagsl-...@yahoo.com.arwrote:
En Wed, 02 May 2007 02:53:55 -0300, elventear <elvent...@gmail.com
escribió:
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?
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.

May 2 '07 #4

P: n/a
En Wed, 02 May 2007 11:46:29 -0300, elventear <el*******@gmail.com>
escribió:
On May 2, 1:12 am, "Gabriel Genellina" <gagsl-...@yahoo.com.arwrote:
>En Wed, 02 May 2007 02:53:55 -0300, elventear <elvent...@gmail.com>
escribió:
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?

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.

--
Gabriel Genellina
May 6 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.