473,385 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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

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
Jan 15 '08 #1
4 1344
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,
--
Miki Tebeka <mi*********@gmail.com>
http://pythonwise.blogspot.com
Jan 15 '08 #2
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
sg*****@ncee.net | 402-438-8958 | http://www.ncee.net

Leading the Campaign for Economic and Financial Literacy

Jan 15 '08 #3
Miki wrote:
http://docs.python.org/lib/module-imp.html
Ah. "imp.find_module". I was looking in "sys" and
path-related places. Thanks.

John Nagle
Jan 15 '08 #4
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
Jan 15 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ian Bicking | last post by:
I think Jason Orendorff's path module is really nice: http://www.jorendorff.com/articles/python/path/ Beats the hell out of os.path, which is an ugly thing indeed. The OO interface means you...
1
by: Hameed Khan | last post by:
hi, i was reading the manual for sys module. i found a description for a function known as exitfunc. and it says the function installed by sys.exitfunc(cleanUpFunc) call will be called when the...
0
by: Thomas Heller | last post by:
Several users have been bitten by the incompatibility of py2exe and Jason Jorendorff's path module at http://www.jorendorff.com/articles/python/path/. I think I have found the bug in...
1
by: Alia Khouri | last post by:
This may have been discussed ad nauseaum before, but every time I use os.path manipulations I miss something like Jason Orrendorf's path.py being in the standard library....
6
by: kimes | last post by:
I've just started digging into how python works.. I found that other mudules are clearly declared like one file per a module.. But the only os.path doesn't have their own file.. ye I know is...
70
by: Michael Hoffman | last post by:
Many of you are familiar with Jason Orendorff's path module <http://www.jorendorff.com/articles/python/path/>, which is frequently recommended here on c.l.p. I submitted an RFE to add it to the...
17
by: chris.atlee | last post by:
Hi there, I haven't seen this topic pop up in a while, so I thought I'd raise it again... What is the status of the path module/class PEP? Did somebody start writing one, or did it die? I...
2
by: andybak | last post by:
Hi, I know this has been consigned to oblivion by the BDFL but I'm rather addicted to it's use. I notice the original site is no longer there. Has anyone got a cached copy of the page that I can...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.