Why not just show the out-of-range index?

BJörn Lindqvist bjourne at gmail.com
Mon Dec 4 18:49:30 EST 2006


On 12/4/06, Terry Reedy <tjreedy at udel.edu> wrote:
> While Fredrik's reply is a bit short, as is sometimes his habit,
> here are some things that appear to me to not have been thought through
> enough:
> 1. some negative indexes are legal.

That could be fixed. Just substract len(L) from i if i < 0.

> 2. replacing short inline code with a function call on *every* index lookup
> will slow down the interpreter a bit.

I can't notice any difference. On my machine, Python is compiled with
-O3 which probably inlines the function.

> 3. will the same check code work for even all built-in sequences?

Atleast for tuple, string and list, they can be downcasted to
PyVarObjects. So yes.

> 4. how does index checking fit in with slice checking?

When does slicing throw IndexErrors?

> with both the knowledge and motivation to do so.  But insulting such people
> is not helpful.

Agreed. I don't think insulting people is helpful at all, but I don't
think "Russ" is the only one in this thread that should learn that.

-- 
mvh Björn



More information about the Python-list mailing list