[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Is there some Python function that searches "sys.path" for a module?

John Nagle

1/15/2008 6:54:00 AM

Python's own loader searches "sys.path" for module names, but is there
some function that makes that search functionality accessible to
Python programs? I need the absolute pathname of a module, with the
search being done exactly the same way "import" does it. The loader for
"egg" files has this functionality, but I'd like to find out if there's
a standard way to do this before looking into that source code.

Also, it seems that the environment variable "PYTHONPATH" applies to
"import", but not to the starting module named on the Python command
line. Is that correct? Thanks.

John Nagle
4 Answers

Miki

1/15/2008 7:03:00 AM

0

Hello John,

>    Python's own loader searches "sys.path" for module names, but is there
> some function that makes that search functionality accessible to
> Python programs?  I need the absolute pathname of a module, with the
> search being done exactly the same way "import" does it.  The loader for
> "egg" files has this functionality, but I'd like to find out if there's
> a standard way to do this before looking into that source code.
>
>    Also, it seems that the environment variable "PYTHONPATH" applies to
> "import", but not to the starting module named on the Python command
> line.  Is that correct?  Thanks.
http://docs.python.org/lib/modul...

HTH,
--
Miki Tebeka <miki.tebeka@gmail.com>
http://pythonwise.bl...

Shane Geiger

1/15/2008 7:14:00 AM

0

If I understand you correctly, you want this:

module.__file__




John Nagle wrote:
> Python's own loader searches "sys.path" for module names, but is there
> some function that makes that search functionality accessible to
> Python programs? I need the absolute pathname of a module, with the
> search being done exactly the same way "import" does it. The loader for
> "egg" files has this functionality, but I'd like to find out if there's
> a standard way to do this before looking into that source code.
>
> Also, it seems that the environment variable "PYTHONPATH" applies to
> "import", but not to the starting module named on the Python command
> line. Is that correct? Thanks.
>
> John Nagle
>


--
Shane Geiger
IT Director
National Council on Economic Education
sgeiger@ncee.net | 402-438-8958 | http://ww...

Leading the Campaign for Economic and Financial Literacy

John Nagle

1/15/2008 7:43:00 AM

0

Miki wrote:

> http://docs.python.org/lib/modul...

Ah. "imp.find_module". I was looking in "sys" and
path-related places. Thanks.

John Nagle

John Nagle

1/15/2008 7:46:00 AM

0

Shane Geiger wrote:
> If I understand you correctly, you want this:
>
> module.__file__

No, this is for a module that isn't loaded, and
I don't want to load it. What I needed was "imp.find_module()".
I don't want to load the module in the current Python instance.
I need its path so I can start it in a subprocess.

John Nagle