[Python-ideas] discontinue iterable strings
Franklin? Lee
leewangzhong+python at gmail.com
Sun Aug 21 03:33:23 EDT 2016
On Aug 21, 2016 1:23 AM, "Nick Coghlan" <ncoghlan at gmail.com> wrote:
> Now, if we were designing a language from scratch today, there's a
> strong case to be made that the *right* way to represent text is to
> have a stream-like interface (e.g. StringIO, BytesIO) around an atomic
> type (e.g. CodePoint, int). But we're not designing a language from
> scratch - we're iterating on one with a 25 year history of design,
> development, and use.
>
> There may also be a case to be made for introducing an AtomicStr type
> into Python's data model that works like a normal string, but
> *doesn't* support indexing, slicing, or iteration, and is instead an
> opaque blob of data that nevertheless supports all the other usual
> string operations. (Similar to the way that types.MappingProxyType
> lets you provide a read-only view of an otherwise mutable mapping, and
> that collections.KeysView, ValuesView and ItemsView provide different
> interfaces for a common underlying mapping)
>
> But changing the core text type itself to no longer be suitable for
> use in text processing tasks? Not gonna happen :)
Thought: A string, in compsci, is, sort of by definition, a sequence of
characters. It is short for "string of characters", isn't it?
If you were to create a new language, and you don't want to think of
strings as char sequences, you might have a type called Text instead.
Programmers could be required to call functions to get iterables, such as
myText.chars(), myText.lines(), and even myText.words().
Thus, the proposal makes str try to be a Text type rather than the related
but distinct String type.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160821/52e95d81/attachment-0001.html>
More information about the Python-ideas
mailing list