mmap as a sequence behavior

Scott David Daniels scott.daniels at acm.org
Thu Jun 29 02:14:02 CEST 2006


Lawrence Oluyede wrote:
> While wrapping mmap indexing/sequence emulation I noticed something
> "strange".   What's got my attention was the fact that passing -1 from 
 > Python does not trigger the exception but is changed to the last
 > positive and valid index....

 > I expect this raise IndexError as reading the C source code but it
 > behaves exactly like sequence types in Python. That's fair to me but I
 > don't get *where* my index is translated.


That is sequence behavior.  The convention of -1 for last, -2 for 
second-to-last, ... is done before it gets to your C code.  I suspect
if you don't define a __len__ method, you'd suppress this.

--Scott David Daniels
scott.daniels at acm.org



More information about the Python-list mailing list