argv[0] manipulation

P_spam_ at draigBrady.com P_spam_ at draigBrady.com
Fri Dec 13 14:36:42 EST 2002


Robin Munn wrote:
> Strange. *VERY* strange. Here's what happens when I try this:
> 
> [rmunn at localhost ~]$ tryme.py
> ['/home/rmunn/bin/tryme.py']

Hmm as Bernhard Herzog pointed out below (and as
I tought previously before you all confused me :-))
the sys.argv[0] (origonally argv[1]) must be
correct so the python interpreter can actually
open the program. So what's happening is:

[padraig at pixelbeat ~/bin]$ cat argv0.py
#!/usr/bin/python
import sys
print sys.argv[0]
[padraig at pixelbeat ~/bin]$ echo $version
tcsh 6.10.00 (Astron) 2000-11-19
[padraig at pixelbeat ~/bin]$ ./argv0.py
./argv0.py
[padraig at pixelbeat ~/bin]$ argv0.py
/home/padraig/bin/argv0.py
[padraig at pixelbeat ~/bin]$ setenv PATH .
[padraig at pixelbeat ~/bin]$ argv0.py
argv0.py

I.E. for tcsh and ksh at least only when the
current directory (i.e. ".") is in the $PATH does the
shell not prepend the (redundant) ./

Pádraig.




More information about the Python-list mailing list