argv[0] manipulation

Erik Max Francis max at alcyone.com
Sat Dec 14 19:02:39 EST 2002


Bernhard Herzog wrote:

> "James Kew" <james.kew at btinternet.com> writes:
>
> > Don't rely on this being portable: the sys module documentation
> > (http://www.python.org/doc/current/lib/module-sys.html) makes no
> > such
> > guarantees about sys.argv[0].
> 
> Then the documentation is wrong, or at least misleading :)

On the contrary!  The documentation is specifying the "contract" between
you and the interpreter.  The documentation is saying, "Don't rely on
this being useful for anything."  You are going the reverse direction,
by observing its behavior in one particular version of one particular
implementation on one particular version of one particular operating
system, and then generalizing and saying that's how it will work.

The documentation is sending you a very important message:  It's saying
not to rely on sys.argv[0] being of much use for anything beyond a vague
hint at what script is running.  Take that advice:  Don't rely on it for
anything important or you will find yourself facing portability problems
on other systems or down the road or both.

In Standard lingo, the documentation is dictating that the contents of
sys.argv[0] are implementation defined.  You shouldn't rely on it for
anything.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ Custom reconciles us to everything.
\__/ Edmund Burke
    Computer science / http://www.alcyone.com/max/reference/compsci/
 A computer science reference.



More information about the Python-list mailing list