From: fredrik at pythonware.com (Fredrik Lundh)
Date: Thu, 22 Apr 1999 12:19:54 GMT
Subject: Directory of current file
References: <Pine.WNT.4.05.9904212159220.191-100000@david.ski.org> <371F0BD2.7D40A957@rubic.com>
Message-ID: <00ee01be8cba$6e98dcb0$f29b12c2@pythonware.com>
X-UID: 489                                                  

Jeff Bauer <jbauer at rubic.com> wrote:
> David Ascher wrote:
> > Tip:  To find out the directory of the currently executing program, use:
> > 
> > import sys, os
> > if __name__ == '__main__':
> >     _thisDir = ''
> > else:
> >     _thisDir = os.path.split(sys.modules[__name__].__file__)[0]
> 
> David, what are the advantages over this?
> 
>   _thisDir = os.path.split(sys.argv[0])[0]

as far as I can tell, David's method works for everything
*except* the main module, while your method works for
the main module, but not for anything else...

how about a combination?

import sys, os
if __name__ == '__main__':
    _thisDir = sys.argv[0]
else:
    _thisDir = sys.modules[__name__].__file__
_thisDir = os.path.split(_thisDir)[0]

</F>





