473,327 Members | 1,952 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,327 software developers and data experts.

import search path

Hello Python list

If a Python program has an import statement like:

import FFT

how do I determine the path to the imported file?

Thanks,
Daniel
Jul 19 '05 #1
3 1524
"SHELTRAW, DANIEL" <sh******@berkeley.edu> writes:
Hello Python list

If a Python program has an import statement like:

import FFT

how do I determine the path to the imported file?


guru% python
Python 2.4.1 (#2, Apr 25 2005, 21:42:44)
[GCC 3.4.2 [FreeBSD] 20040728] on freebsd5
Type "help", "copyright", "credits" or "license" for more information.
py> import FFT
py> import sys
py> sys.modules['FFT'].__file__
'/usr/opt/lib/python2.4/site-packages/Numeric/FFT/__init__.pyc'
<mike

--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Jul 19 '05 #2
Mike Meyer wrote:
"SHELTRAW, DANIEL" <sh******@berkeley.edu> writes:
If a Python program has an import statement like:

import FFT

how do I determine the path to the imported file?

guru% python
Python 2.4.1 (#2, Apr 25 2005, 21:42:44)
[GCC 3.4.2 [FreeBSD] 20040728] on freebsd5
Type "help", "copyright", "credits" or "license" for more information.
py> import FFT
py> import sys
py> sys.modules['FFT'].__file__
'/usr/opt/lib/python2.4/site-packages/Numeric/FFT/__init__.pyc'


No need for the detour through sys:
import FFT
FFT.__file__

'C:\\Python24\\lib\\site-packages\\Numeric\\FFT\\__init__.pyc'

Kent
Jul 19 '05 #3
Mike Meyer wrote:
"SHELTRAW, DANIEL" <sh******@berkeley.edu> writes:
If a Python program has an import statement like:
import FFT

how do I determine the path to the imported file?
guru% python
Python 2.4.1 (#2, Apr 25 2005, 21:42:44)
[GCC 3.4.2 [FreeBSD] 20040728] on freebsd5
Type "help", "copyright", "credits" or "license" for more information.
py> import FFT
py> import sys
py> sys.modules['FFT'].__file__
'/usr/opt/lib/python2.4/site-packages/Numeric/FFT/__init__.pyc'

Much shorter is: import FFT
FFT.__file__ <<the path in question>>

Note that (after the above): import sys
sys.modules['FFT'] is FFT

True

--Scott David Daniels
Sc***********@Acm.Org
Jul 19 '05 #4

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

Similar topics

1
by: Csaba Henk | last post by:
Hello! I use Python 2.2.2 on Linux. I met the following issue: Say I have the module mymod and the script myprog.py in /mydir. myprog.py imports mymod. If I create a symlink /foo/myprog2.py...
4
by: Jesse B. | last post by:
I have just begun to learn python using o'reilly's Learning Python, and in chapter 3 it talks about importing modules. It has me make modules to practice using the 'import' and 'from' statements...
6
by: John J. Lee | last post by:
I'm tearing my hair out at what seems like weird import behaviour I'm getting from Python's stdlib test script, regrtest.py (not for the first time: seem to have forgotten the resolution from last...
3
by: Ilias Lazaridis | last post by:
I am within a directory \doc\template\ I launch script.py within this script.py, I like to import a module from the doc directory. this here does not work:
7
by: Ron Adam | last post by:
from __future__ import absolute_import Is there a way to check if this is working? I get the same results with or without it. Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) on win 32 ...
3
by: SMALLp | last post by:
Hy! I'm new in Linux, and i feel little less newer in python. I need advice and help. I'm making an application witch purpose is irrelevant. It has a lot of code for now and I've only made...
2
by: tinnews | last post by:
I'm trying to minimise the overheads of a small Python utility, I'm not really too fussed about how fast it is but I would like to minimise its loading effect on the system as it could be called...
0
by: Laszlo Nagy | last post by:
ohad frand wrote: So this is what you have: /1/tmp1.py /1/tmp2.py /2/tmp1.py /2/tmp2.py
8
by: tow | last post by:
I have a python script (part of a django application, if it makes any difference) which is exhibiting the following behaviour: import my_module # succeeds imp.find_module("my_module") # fails,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...

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.