[Python-3000] Making more effective use of slice objects in Py3k

Guido van Rossum guido at python.org
Sun Aug 27 17:55:05 CEST 2006


On 8/26/06, Josiah Carlson <jcarlson at uci.edu> wrote:
>
> "Jim Jewett" <jimjjewett at gmail.com> wrote:
> > With stringviews, you wouldn't need to be reindexing from the start of
> > the original string.  The idiom would instead be a generalization of
> > "for line in file:"
> >
> >     while data:
> >         chunk, sep, data = data.partition()
> >
> > but the partition call would not need to copy the entire string; it
> > could simply return three views.
>
> Also, with a little work, having string views be smart about
> concatenation (if two views are adjacent to each other, like chunk,sep
> or sep,data above, view1+view2 -> view3 on the original string), copies
> could further be minimized, and the earlier problem with readline, etc.,
> can be avoided.

But this assumes that string views are 99.999% indiscernible from
regular strings -- if operations can return a copy or a view depending
on how things happen to be laid out in memory, It should be trivial to
write code that doesn't care whether it gets a string or a view.

This works for strings (which are immutable) but these semantics are
unacceptable for mutable objects -- another reason to doubt that it
makes sense to generalize the idea of views to all sequences, or to
involve a change to the slice object in the design.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list