On Wed, Sep 15, 2010 at 10:09 AM, raymond.hettinger <python-check...@python.org> wrote: > +The formal syntax makes no special provision for negative indices in > +sequences; however, built-in sequences all provide a :meth:`__getitem__` > +method that interprets negative indices by adding the length of the sequence > +to the index (so that ``x[-1]`` selects the last item of ``x``). The > +resulting value must be a nonnegative integer less than the number of items > in > +the sequence, and the subscription selects the item whose index is that value > +(counting from zero). Since the support for negative indices and slicing > +occurs in the object's :meth:`__getitem__` method, subclasses overriding > +this method will need to explicitly add that support.
Perhaps mention the slice.indices(len) helper for performing the standard conversion from negative indices to positive ones when dealing with negative indices *in* slices? Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com