Yes, this is a known problem (should've been in the latest FAQ but I
forgot to add it). It's fixed in 1.2. Here's a patch:
========================================================================
RCS file: /ufs/guido/CVSROOT/python/Python/bltinmodule.c,v
retrieving revision 2.59
retrieving revision 2.60
diff -c -r2.59 -r2.60
*** 2.59 1995/01/02 19:03:58
--- 2.60 1995/01/04 19:11:35
***************
*** 922,937 ****
}
if (coerce(&v, &w) != 0)
return NULL;
! if (z!=None) {
! if (coerce(&w, &z) != 0)
! return NULL;
! if (coerce(&v, &z) != 0)
! return NULL;
}
- x = (*v->ob_type->tp_as_number->nb_power)(v, w, z);
DECREF(v);
DECREF(w);
- if (z!=None) {DECREF(w); DECREF(v); DECREF(z); DECREF(z);}
return x;
}
--- 922,952 ----
}
if (coerce(&v, &w) != 0)
return NULL;
! if (z == None) {
! x = (*v->ob_type->tp_as_number->nb_power)(v, w, z);
! }
! else {
! object *v1, *z1, *w2, *z2;
! x = NULL;
! v1 = v;
! z1 = z;
! if (coerce(&v1, &z1) != 0)
! goto error2;
! w2 = w;
! z2 = z1;
! if (coerce(&w2, &z2) != 0)
! goto error1;
! x = (*v1->ob_type->tp_as_number->nb_power)(v1, w2, z2);
! DECREF(w2);
! DECREF(z2);
! error1:
! DECREF(v1);
! DECREF(z1);
! error2:
! ;
}
DECREF(v);
DECREF(w);
return x;
}
========================================================================
> I also noticed a strange behavior while trying to use the 'getopts' module.
> I wrote the following code (to file p.py):
>
> #! /usr/local/bin/python
> import sys,getopt
> opts, args = getopt.getopt(sys.argv[1:],'q')
> print opts
>
> and then try to execute it like this:
>
> > p.py -q
>
> and got the python interpreter illegal option message. I tried the
> same code at work (under SunOs) and it works fine.
> Any ideas of what is wrong ?
This is in the FAQ:
3.6. Q. The python interpreter complains about options passed to a
script (after the script name).
A. You are probably linking with GNU getopt, e.g. through -liberty.
Don't. The reason for the complaint is that GNU getopt, unlike System
V getopt and other getopt implementations, doesn't consider a
non-option to be the end of the option list. A quick (and compatible)
fix for scripts is to add "--" to the interpreter, like this:
#! /usr/local/bin/python --
You can also use this interactively:
python -- script.py [options]
Note that a working getopt implementation is provided in the Python
distribution (in Python/getopt.c) but not automatically used.
--Guido van Rossum, CWI, Amsterdam <mailto:Guido.van.Rossum@cwi.nl>
<http://www.cwi.nl/cwi/people/Guido.van.Rossum.html>