location of a module's directory

Dave Berkeley dave at rotwang.freeserve.co.uk
Sat Apr 6 04:21:38 EST 2002


Yes, thanks. My mistake was only looking at the module sys, which is of
course built in, so it does not have a __file__ attribute. Thanks.

Dave

"Joonas Paalasmaa" <joonas at olen.to> wrote in message
news:3CADBDB4.7090007 at olen.to...
> Dave Berkeley wrote:
> > Is there a way to discover where a module was loaded from?
> >
> > I want to include a text configuration file with a .dll, and place them
in
> > the same directory. If the module knows where it was loaded from it will
be
> > able to find the config file.
> >
> > If you do (Python 2.1.1)
> >
> >
> >>import sys
> >>print sys.modules
> >
> >
> > you can get a dictionary of loaded modules, and a description, which
> > includes the path the module was loaded from. However, I can find no way
of
> > accessing this information programmatically.
>
> Are you looking for this?
>
> Python 2.2a3 (#23, Sep  7 2001, 01:43:22) [MSC 32 bit (Intel)] on win32
> Type "copyright", "credits" or "license" for more information.
> IDLE Fork 0.8 -- press F1 for help
>  >>> import cgi
>  >>> cgi.__file__
> 'C:\\Python22\\lib\\cgi.py'
>





More information about the Python-list mailing list