sys.argv[0] - Returns path and filename.

Guy guy at lightwork.co.uk
Thu Jun 27 14:32:19 CEST 2002


Hi

I work on multiple platforms, at the moment, I have python installed
on my win32 box which I mainly work on, a MacOSX box and a linux box
which has a very old version installed on it.

The only major problem that I have come across at the moment is the
argv[0], on my win32 box it retruns the path and a filename, on the
mac osx and the linux only the filename are returned.

How do I get the current path of the script I am running, on the mac
osx and the linux box ? (Any work around would be great, I don't want
to have to hardcode the path into the script, or even give the path as
an argument,I want the script to know where it is.)

I've tryed searching for this but can't find it anywhere. 

Example script called arguments.py :
import sys
print sys.argv[0]

Result Win32 :
>>> D:\TestArg\arguments.py

Result Mac OSX : 
MacOSX% python arguments.py
arguments.py

Result Linux : 
linux% python arguments.py
arguments.py



More information about the Python-list mailing list