[Python-bugs-list] [Bug #116397] Python takes cmd line options after module name for itself

noreply@sourceforge.net noreply@sourceforge.net
Mon, 9 Oct 2000 05:37:06 -0700

Bug #116397, was updated on 2000-Oct-09 00:31
Here is a current snapshot of the bug.

Project: Python
Category: Core
Status: Closed
Resolution: Invalid
Bug Group: Not a Bug
Priority: 5
Summary: Python takes cmd line options after module name for itself

Details: Let the file foo.py be:

import sys
print sys.argv

Here is the behavior for version 1.6:

$ python1.6 foo.py 
$ python1.6 foo.py john doe
['foo.py', 'john', 'doe']
$ python1.6 foo.py john doe -o /dev/null 
[... long insult message to say that Python does not recognize the "-o" option ...]
$ python1.6 foo.py -- john doe -o /dev/null 
['foo.py', 'john', 'doe', '-o', '/dev/null']
           ^-- NOTE: an argument WAS stripped

And that was the behavior for version 1.5.2:

$ python1.5 foo.py 
$ python1.5 foo.py john doe
['foo.py', 'john', 'doe']
$ python1.5 foo.py john doe -o /dev/null 
['foo.py', 'john', 'doe', '-o', '/dev/null']
$ python1.5 foo.py -- john doe -o /dev/null 
['foo.py', '--', 'john', 'doe', '-o', '/dev/null']
           ^-- NOTE: argument NOT stripped

The manual page says:
    python [options] script [script args]

so strictly speaking this is a bug since arguments starting with '-' are located AFTER the script argument, as specified in the manual page.

Is the bug in Python or the manual page ? (in the latter case this means a change in the command line syntax, and we will have to make scripts that distinguish Python versions when we want to make commands that accept options)


Date: 2000-Oct-09 05:37
By: gvanrossum

You must accidentally have linked Python with the GNU version of getopt.  GNU getopt is evil! Try using getopt.c that's in the Python distribution.

(The configure script tests for this, but it's possible that the link library order used eventually is different from what is used in the configure test.)

For detailed info, follow this link: