[Python-Dev] Iterable String Redux (aka String ABC) (original) (raw)

Georg Brandl g.brandl at gmx.net
Tue May 27 22:44:59 CEST 2008


Antoine Pitrou schrieb:

(just my 2 eurocents)

Guido van Rossum <guido python.org> writes:

I'm not against this, but so far I've not been able to come up with a good set of methods to endow the String ABC with. If we stay minimalistic we could consider that the three basic operations that define a string are: - testing for substring containment - splitting on a substring into a list of substrings - slicing in order to extract a substring

Which gives us ['contains', 'split', 'getitem'], and expands intuitively to ['contains', 'find', 'index', 'split', 'rsplit', 'getitem'].

I'd argue that "find" is more primitive than "split" -- split is intuitively implemented using find and slicing, but implementing find using split and len is unintuitive. (Of course, "index" can be used instead of "find".)

Another problem is that not everybody draws the line in the same place -- how should instances of bytes, bytearray, array.array, memoryview (buffer in 2.6) be treated? In the followup of the flatten() example, bytes and bytearray should be Strings, but array.array and memoryview shouldn't. array.array is really a different kind of container rather than a proper string, and as for memoryview... well, since it's not documented I don't know what it's supposed to do :-)

This is really a problem -- since the PEP 3118 authors don't seem to bother, I'll have to write up something based on the PEP, but I don't know if it is still up-to-date.

Georg



More information about the Python-Dev mailing list