Is there a common function to do this? Right now I'm just doing the following (and overriding __len__)
idx < 0:
idx = len(self) + idx
if idx < 0 or idx >= len(self):
raise IndexError, "array index (%d) out of range [0, %d)" %(idx, len(self))
Is there a common function to do this? Right now I'm just doing the following (and overriding __len__)
idx < 0:
idx = len(self) + idx
if idx < 0 or idx >= len(self):
raise IndexError, "array index (%d) out of range [0, %d)" %(idx, len(self))
That seems fine to me. I don't think there is a better or built-in way to do that; overriding is about providing your own functionality, after all.
Edited to remove rather stupid suggestion.