Module directory

Alex Martelli aleaxit at
Fri Sep 8 11:28:43 CEST 2000

"Gilles Lenfant" <glenfant at> wrote in message
news:8p8l43$piv$1 at
> Hi,
> I'm looking for a simple (and portable) way to get the path of the module
> from within a function it contains.

A module has a __file__ attribute that gives the complete path
to the file from which the module has been loaded.  Therefore:


when called from any function (with an import os.path in the
module, of course:-) will give the directory-name from which
the module that contains the function was loaded (this assumes
the function's func_globals have not been tampered with, of
course, but who ever does that?).


More information about the Python-list mailing list