Entry
Directory of current file
Jul 5th, 2000 09:59
Nathan Wallace, unknown unknown, Hans Nowak, Snippet 85, Fredrik Lundh
"""
Packages: files
"""
"""
> > 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]
print _thisDir