471,084 Members | 962 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Problem with inspect.getfile

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
4 1584
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
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
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
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.

Similar topics

7 posts views Thread by Robin Becker | last post: by
11 posts views Thread by It's me | last post: by
18 posts views Thread by George Sakkis | last post: by
3 posts views Thread by David Blasdell | last post: by
reply views Thread by Ron Adam | last post: by
reply views Thread by Kenny | last post: by
12 posts views Thread by NOO Recursion | last post: by
3 posts views Thread by Rafe | last post: by
reply views Thread by rajasankar | last post: by

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.