location of a module's directory

Donnal Walter donnal at donnal.net
Fri Apr 5 13:22:51 EST 2002


"Dave Berkeley" <dave at rotwang.freeserve.co.uk> wrote in message news:<a8k1cb$s9v$1 at news6.svr.pol.co.uk>...
> 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.

Will something like this work?

import os
def Main():
    try:
        myPath = os.path.dirname(__file__)
        print myPath
    except:
        pass


Donnal Walter
Arkansas Children's Hospital



More information about the Python-list mailing list