Antoine Pitrou schrieb:
(just my 2 eurocents)
Guido van Rossum <guido <at> 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
_______________________________________________
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