GetOpts problems on linux/PC

allen@ksr.com
Thu, 17 Feb 1994 11:54:33 -0500

I have loaded python 1.0.0 and patch 1 onto my home PC 486/66DX2
running Linux (I don't know the slackware, gcc, etc revision numbers
of the top of my head). I noticed very soon that the linux version of
"getopt" is not quite the same as it seems to be on the machines at
work (HP-735, Sun4, Solbourne, KSR1). For instance, I create script
"test.py" =

##########
import getopt, sys
swt, arg = getopt.getopt(sys.argv[1:], 'd:vh')
print "swt = ", swt
print "arg = ", arg
##########

and I run it like this under HP/UX:

flash % python test.py -d 1
swt = [('-d', '1')]
arg = []

BUT when I run this on under linux I get:

beach % python test.py -d 1
swt = []
arg = ['1']

The problem is that getopt in linux searches *past* the first
argument "test.py", until it discovers a switch '-d' which happens to
match a switch that python uses.

I fixed this by modifying Python/pythonmain.c to parse the command
arguments manually (thus ignoring getopts entirely).

I haven't noticed anyone else mention this problem, so I'll assume
no one else is affected. But if you would like a patch file or a new
copy of this affected file I would be happy to mail it to you. I'd
be happy to rewrite a local version of getopt that behaves as
expected, but I suspect this is a local problem, and it is trivial to
fix, anyway.

On another note, Python works great on linux. I'm working on some
python programs at work and at home, passing python code i486 and
HP-735 (there is about a 2.5X performance improvement on the HP over
486DX2/66), but functionally there appear to be no compatibility
problems otherwise.

Good show Guido.

thanking-the-hardware-god-for-fast-computers-so-I-can-use-python
instead-of-C++-for-every-thing-ly yr's SteveA

----
\
o/\_ Steve Allen (allen@ksr.com)
<\__,\ Kendall Square Research
"> | Waltham, MA
|
\ "This Ain't No @#$%! Weenie Roast!"