program path

Gerhard Häring gh at ghaering.de
Sun Jun 8 13:10:37 EDT 2003


Peter Hansen wrote:
> Steven Taschuk wrote:
> 
>>Quoth Peter Hansen:
>>  [...]
>>
>>>scriptPath = os.path.abspath(sys.argv[0])
>>
>>On machines where sys.argv[0] isn't the absolute path already,
>>might it not be the name-as-invoked, and thus ought to be resolved
>>by scanning the $PATH (or equivalent) rather than as relative to
>>the current directory?
> 
> 
> I'm not certain.  Under Win9x, you likely can't invoke the 
> script unless you specify the full path (even using the file
> assocation probably translates to the same thing).  Under
> Linux, experimentation suggests to me that if you invoke
> it from the PATH, sys.argv[0] contains the full path already
> and the abspath() call is redundant, if harmless.
> 
> Can anyone with access to a WinNT/XP machine that can invoke
> scripts without explicitly specifying "python.exe" in the 
> command line add to this?

#v+
C:\>copy con: tmp\x.py
import sys
print sys.argv[0]
^Z
         1 file(s) copied.

C:\>tmp\x.py
C:\tmp\x.py

C:\>ver

Microsoft Windows XP [Version 5.1.2600]
#v-

-- Gerhard





More information about the Python-list mailing list