>From reading many of the suggestions in this list (including some of my own, 
>of course) there seem to be a lot of us in the Python coder community who find 
>the current behavior of strings being iterable collections of single-character 
>strings to be somewhat problematic. At the same time, trying to change that 
>would obviously have vast consequences, so not something that can simply be 
>changed, even with at a major version boundary.

I propose that we start by making a small, safe step in the right direction so 
we can maybe reach the bigger goal in a far future release (e.g. 5.x or 6.x).

The step I propose is to add a `chars` method that returns a sequence 
(read-only view) of single-character strings that behaves exactly the same as 
`str` currently does when treated as a collection. Encourage developers to use 
that for iterating over characters in a string instead of iterating over the 
string directly. In maybe Python 4 or 5, directly using an `str` instance as a 
collection could become a warning.

BTW, while adding `chars`, it might also be nice to have `ords` which would be 
a view of the string's character sequence as `ord` integer values.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/WKEFHT4JYCL2PMZ5LB6HJRLVP3OGZI56/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to