[Python-Dev] PEP397 no command line options to python?

Sam Partington sam.partington at gmail.com
Mon Oct 17 12:10:58 CEST 2011


Hello all,

I was surprised to see that the excellent pylauncher doesn't do the
magic shebang processing if you give it any python command line
options.  e.g. Given

#!/usr/bin/env python2.6
import sys
print(sys.executable)

C:\>py test.py
C:\Python26\python.exe
C:\>py -utt test.py
C:\Python27\python.exe

It is spelled out that it shouldn't do so in the pep :

  "Only the first command-line argument will be checked for a shebang line
   and only if that argument does not start with a '-'."

But I can't really see why that should be the case.  What is the
rational behind this? It is very surprising to the user that adding a
simple option like -tt should change the way the launcher behaves.
The PEP also states that the launcher should show the python help if
'-h' is specified :

    "If the only command-line argument is "-h" or "--help", the launcher will
    print a small banner and command-line usage, then pass the argument to
    the default Python.  This will cause help for the launcher being printed
    followed by help for Python itself.  The output from the launcher will
    clearly indicate the extended help information is coming from the
    launcher and not Python."

To me that would suggest to end users that they can use any of the
command line options with the launcher, and they should behave as if
you had called python directly.

I am directing this to python-dev because this pylauncher is merely
implementing the PEP as it currently stands, so the PEP would ideally
need to be modified before the launcher.

I would change the that first paragraph of the PEP to read something like :

"
    The first command-line argument not beginning with a '-' will be checked
    for a shebang line, but only if :

    * That command-line argument is not preceded by a '-c' or '-m',
and providing

    * There is no explicit version specifier, e.g. -2.7 as documumented later in
      this PEP.
"

Incidentally whilst implementing this I also noticed a bug in the
pylauncher whereby the py launcher would incorrectly treat "py t3" as
a request for python version as if '-3' had been specified.  I have a
small patch that fixes this and implements the above for pylauncher
with extra tests if there is interest.

Sam

PS I have been lurking for a while, hello everyone.


More information about the Python-Dev mailing list