Finding startup files

Robert Kern rkern at ucsd.edu
Wed May 11 18:18:36 EDT 2005


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.

-- 
Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter




More information about the Python-list mailing list