By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,908 Members | 1,860 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,908 IT Pros & Developers. It's quick & easy.

import search path

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
"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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.