program path

Bengt Richter bokr at
Mon Jun 9 01:25:16 CEST 2003

On Sat, 7 Jun 2003 23:04:41 -0600, Steven Taschuk <staschuk at> 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?
ISTM the name-as-invoked is a named arg (script file name -- relative or absolute)
whose meaning is relative to the cwd of the running python interpreter instance, and
therefore should not be resolved through $PATH, unless that is what the python interpreter
does (which I don't think it does).

It might be an interesting command line option to pass to python, though, letting it do
a search according to whatever search path might make sense. I could see using the system's $PATH,
but I could also see a more limited search in the python tree. Maybe both options.

BTW, this seems to be a minor buglet:

[16:25] C:\pywk\clp>python -c "import sys,os; print os.path.realpath(sys.argv[0])"


[16:25] C:\pywk\clp>python -u -c "import sys,os; print os.path.realpath(sys.argv[0])"

(note that -u is excluded, as IWT -c should be).
Bengt Richter

More information about the Python-list mailing list