[Python-3000] Making more effective use of slice objects in Py3k (original) (raw)

Jim Jewett jimjjewett at gmail.com
Sun Aug 27 03:59:25 CEST 2006


On 8/26/06, Josiah Carlson <jcarlson at uci.edu> wrote:

Nick Coghlan <ncoghlan at iinet.net.au> wrote:

> There are a couple of existing workarounds for > this: buffer() objects, and the start/stop arguments > to a variety of string methods. Neither of these is > particular convenient to work with, and buffer() is > slated to go away in Py3k.

Ahh, but string views offer a significantly more reasonable mechanism.

As I understand it, Nick is suggesting that slice objects be used as a sequence (not just string) view.

string = stringview(string) ... We can toss all of the optional start, stop arguments to all string functions, and replace them with either of the following: result = stringview(string, start=None, stop=None).method(args)

string = stringview(string) result = string[start:stop].method(args)

Under Nick's proposal, I believe we could replace it with just the final line.

result = string[start:stop].method(args)

though there is a chance that (when you want to avoid copying) he is suggesting explicit slice objects such as

view=slice(start, stop)
result = view(string).method(args)

-jJ



More information about the Python-3000 mailing list