Questions regarding design decisions in listobject.c

Courageous jkraska1 at san.rr.com
Sun Jun 4 17:26:07 EDT 2000


Thomas Wouters wrote:
> 
> On Sun, Jun 04, 2000 at 08:19:10PM +0000, Courageous wrote:
> 
> > 1. For slice operations, ilow/ihigh indices which undeflow
> > or overflow the list in question are reset to the edges
> > of the list. Why was it that PyExc_IndexError wasn't
> > thrown instead?
> 
> I believe this was done to avoid having to use a lot of len() and 'or''s
> inside indexes. If you want the first ten characters, or less, of a string,
> currently you do:

Ahhhh. That makes sense. Well that throws all my "better"
exception raising code out the window, now doesn't it? :)-


C/

> Actually, it's very intuitive, if you see the start and end index of the
> slice not as items, but as the gaps between the items.

Well, yeah, but [0:3] as "element zero through three, inclusive"
is about as intuitive as you can get. While I understand completely
how the current implementation works (reading the source code and
all, dontcha know), I still fail to see *why* this was chosen.
I'm presuming there must be some conditions where this particular
idiom was required or caused for nasty syntactic transformations
if it wasn't used?


C/



More information about the Python-list mailing list