Finding startup files

jeff elkins jeffelkins at earthlink.net
Wed May 11 14:54:40 EDT 2005


On Wednesday 11 May 2005 10:18 pm, Robert Kern wrote:
> jeff elkins wrote:
> > On Wednesday 11 May 2005 04:44 pm, Grant Edwards wrote:
> >>On 2005-05-11, hemagician at gmail.com <hemagician at gmail.com> wrote:
> >>>The following script demonstrates a method that should work for you. I
> >>>believe it is entirely cross-platform.
> >>>
> >>>#! /usr/bin/python
> >>>
> >>>import sys
> >>>import os
> >>>
> >>>print os.path.abspath(os.path.dirname(sys.argv[0]))
> >>
> >>That will probably work most of the time, but...
> >>
> >> 1) you're not gauranteed that argv[0] contains the application
> >>    path/filename.
> >>
> >> 2) the directory containing the executable is not where
> >>    configuration files are supposed to be stored under
> >>    Unix/Linux.
> >
> > Thanks Grant,
> >
> > I live and develop in Linux, but unfortunately, 99.99% of the users of
> > this particular application (analysis of medical laboratory data) will be
> > working with Windows.
> >
> > I'm totally new to Python (obvious,yes?) so how might argv[0] fail?
>
> If I make a symbolic link to the executable script and run it using that
> link, sys.argv[0] will give the filename of that link, not the real file
> it points to.


Thanks. I just tested that and it does indeed fail.

Jeff



More information about the Python-list mailing list