[Python-Dev] slicing of structseq objects fails
Fredrik Lundh
fredrik@pythonware.com
Tue, 30 Oct 2001 23:57:27 +0100
jack wrote:
> > The following code fails (G4, MacOS 9.2.1) in Classic MacPython 2.2b1:
> >
> > import time
> >
> > currUTCTuple= time.gmtime(time.time())
> > print "currUTCTuple=%r" % (currUTCTuple,)
> > print "currUTCTuple[3:6]=%r" % (currUTCTuple[3:6],)
> > fmtTime = "%s:%02i:%02i" % currUTCTuple[3:6]
> > print "formatted time = ", fmtTime
> >
> > It displays (<NULL>, <NULL>, <NULL>) for currUTCTuple[3:6],
also note:
>>> import time
>>> tm = time.gmtime()
>>> tm
(2001, 10, 30, 22, 54, 16, 1, 303, 0)
>>> tm.tm_year
2001
>>> tm[:6]
(2001, 10, 30, 22, 54, 16)
>>> tm[3:6]
(<nil>, <nil>, <nil>)
in structseq_slice,
for(i = low; i < high; ++i) {
PyObject *v = obj->ob_item[i];
Py_INCREF(v);
PyTuple_SET_ITEM(np, i, v);
}
should be:
for(i = low; i < high; ++i) {
PyObject *v = obj->ob_item[i];
Py_INCREF(v);
PyTuple_SET_ITEM(np, i-low, v);
}
</F>