Finding Script Directory

Fuzzyman michael at foord.net
Wed Jul 7 16:19:22 EDT 2004


"Larry Bates" <lbates at swamisoft.com> wrote in message news:<MK6dneiIPcyhn3HdRVn-uA at comcast.com>...
> Would os.curdir() help?  It as least tells you the
> current directory.  My solution to what I think is
> your problem is to put an installdirectory= statement
> in my configuration file that gets updated when the
> application is installed.  That way I always know
> where the script is installed.  I use Inno Installer
> and it is very easy to update configuration files
> during installation.
> 
> HTH,
> Larry Bates
> Syscon, Inc.
> 
This might be the answer to my problem, part of the problem I'm trying
to solve is an install of a py2exe'd program that is installed with
innosetup.

I'll have to look into this.
Otherwise the magic with os.path.abspath(sys.argv[0]) should do the
trick...

Regards,

Fuzzy

> "Fuzzyman" <michael at foord.net> wrote in message
> news:8089854e.0407070426.2fb90f95 at posting.google.com...
> > What's the best, cross platform, way of finding out the directory a
> > script is run from ?
> >
> > I've googled a bit, but can't get a clear answer.
> >
> > On sys.argv[0] the docs say :
> > argv[0] is the script name (it is operating system dependent whether
> > this is a full pathname or not).
> >
> > So this doesn't seem to be the answer.
> >
> > The script directory is always *somewhere* in sys.path - but not
> > always in position 0. If you use py2exe then sys.path[0] is the
> > zipfile it does the imports from !!
> >
> > Regards,
> >
> > Fuzzy
> >
> > http://www.voidspace.org.uk/atlantibots/pythonutils.html



More information about the Python-list mailing list