Negative array indicies and slice()

Chris Angelico rosuav at gmail.com
Mon Oct 29 09:53:13 EDT 2012


On Mon, Oct 29, 2012 at 5:01 PM, Andrew Robinson
<andrew3 at r3dsolutions.com> wrote:
>  Looking at some of the online programming notes -- a slice apparently
> doesn't use an integer storage variable that is capable of arbitrary
> expansion. =-O -- and hence, won't work for very large sized lists.  That
> actually explains some crashes I have noted in the past when working with 20
> million element lists that I wanted a slice of.  I had *plenty* of ram on
> that system.

Can you provide links to these notes? I'm looking at
cpython/Include/sliceobject.h that has this comment:

/*

A slice object containing start, stop, and step data members (the
names are from range).  After much talk with Guido, it was decided to
let these be any arbitrary python type.  Py_None stands for omitted values.
*/

Also, the code for slice objects in CPython works with Py_ssize_t (a
signed quantity of the same length as size_t), which will allow at
least 2**31 for an index. I would guess that your crashes were nothing
to do with 20 million elements and slices.

ChrisA



More information about the Python-list mailing list