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

Guy guy at
Thu Jun 27 08:32:19 EDT 2002


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 :
import sys
print sys.argv[0]

Result Win32 :
>>> D:\TestArg\

Result Mac OSX : 
MacOSX% python

Result Linux : 
linux% python

More information about the Python-list mailing list