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

Fredrik Lundh fredrik at pythonware.com
Mon Dec 4 01:58:25 EST 2006


Russ wrote:

> Holy cow! I can't believe that many changes would be necessary unless
> the IndexError exception is scattered all over the place. I would hope
> that one well-placed change could fix the bulk of cases.

when you write x[i], the interpreter makes no assumptions about x and i 
and len(x); it just calls the corresponding method (__getitem__), either 
directly, or via a C-level internal slot.

there's no way to generate the error message you want in a single place 
without changing the semantics of x[i].

</F>




More information about the Python-list mailing list