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

J

John Nagle

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
 
M

Miki

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/module-imp.html

HTH,
 
S

Shane Geiger

If I understand you correctly, you want this:

module.__file__




John said:
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
(e-mail address removed) | 402-438-8958 | http://www.ncee.net

Leading the Campaign for Economic and Financial Literacy
 
J

John Nagle

Shane said:
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
 

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,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top