How to get the full path of imported module?

Dave Brueck dbrueck at edgix.com
Wed Nov 15 10:28:49 EST 2000


> Without searching through every element in sys.path, is there
> any way to get the full path of imported modules?
> I think I've glimpsed it somewhere but can't come up with
> it.

I'm not sure if this is what you're looking for, but maybe it'll help:

>>> import htmllib
>>> htmllib.__file__
'C:\\Python20\\lib\\htmllib.pyc'

(notice that it's using the .pyc and not the .py)

You can also use imp to get info back on any module (imported or not):

>>> import imp
>>> imp.find_module('htmllib')
(<open file 'C:\Python20\lib\htmllib.py', mode 'r' at 011351E8>, 
 'C:\\Python20\\lib\\htmllib.py', 
 ('.py', 'r', 1))

-Dave




More information about the Python-list mailing list