[issue1617699] slice-object support for ctypes Pointer/Array

Thomas Wouters report at bugs.python.org
Thu Aug 30 22:10:18 CEST 2007


Thomas Wouters added the comment:

Well, that's not quite how I implemented the slicing, and it's also not
how the existing simple-slicing was implemented: A negative start index
is taken to mean 0, and a stop index below the start index is taken to
mean 'the start index' (leading to an empty slice.)

However, it isn't too hard to do what I think you want done: a negative
index means indexing before the pointer, not from the end of the
pointer, and missing indices are only okay if they clearly mean '0'
('start' when step > 0, 'stop' when step < 0.)

So:
 P[5:10] would slice from P[5] up to but not including P[10],
 P[-5:5] would slice from P[-5] up to but not including P[5],
 P[:5] would slice from P[0] up to but not including P[5],
 P[5::-1] would slice from P[5] down to *and including* P[0]
but the following would all be errors:
 P[5:]
 P[:5:-1]
 P[:]
 P[::-1]

Does that sound like what you wanted?

_____________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1617699>
_____________________________________


More information about the Python-bugs-list mailing list