Retrieving the full command line

Chris Angelico rosuav at
Thu Jan 24 06:06:45 CET 2013

On Thu, Jan 24, 2013 at 3:49 PM, Steven D'Aprano
<steve+comp.lang.python at> wrote:
> Note however that there is an ambiguity between calling "python -mspam"
> and calling a script literally named "-mspam". But that same ambiguity
> exists in the shell, so I don't consider it a problem. You cannot call a
> script named -mspam unless you use something like this "python ./-mspam".

Another spanner for your works: "python -- -mspam" succeeds. That sets
argv[0] to '-mspam'.

> People hardly ever care about argv[0]. At least, I don't think I ever
> have. But the OP does, and Python mangling argv[0] is causing him grief
> because it lies, claiming to have called the of his package
> directly when in fact he called it with -m.

Usually when I reference argv[0], $0, or any equivalent, it's for a
usage display - eg:

USAGE: $0 [opts] infile [outfile]
--foo    Fooify the file
--bar    Burn your computer to the ground

So I don't particularly care about symlinks or relative paths (if it
worked once, it'll probably work another time). But ambiguities may be
an issue.


More information about the Python-list mailing list