import search path

Kent Johnson kent37 at tds.net
Wed Jun 22 17:59:32 EDT 2005


Mike Meyer wrote:
> "SHELTRAW, DANIEL" <sheltraw at 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



More information about the Python-list mailing list