find the path of a module

Michael Palmer m_palmer45 at
Tue Sep 16 22:20:03 CEST 2008

On Sep 16, 4:07 pm, vvangelov... at wrote:
> I'd like to know if I can somehow find the path for a module somewhere
> in a the package hierarchy
> for instance if I import my module like so
> from spam.eggs import sausage
> my hypothetical method would return something like
> '/home/developer/projects/spam/eggs/'
> given that module object.

The __file__ attribute is what you want:

>>> import pyPdf
>>> pyPdf.__file__

More information about the Python-list mailing list