[Python-3000] Making strings non-iterable

Steven Bethard steven.bethard at gmail.com
Thu Apr 13 20:16:27 CEST 2006


On 4/13/06, Ian Bicking <ianb at colorstudy.com> wrote:
> I propose that strings (unicode/text) shouldn't be iterable.  Seeing this:
>
> <ul>
>   <li> i
>   <li> t
>   <li> e
>   <li> m
>   <li>
>   <li> 1
> </ul>
>
> a few too many times... it's annoying.  Instead, I propose that strings
> get a list-like view on their characters.

+1.  I don't know how many times I wished I'd gotten an error here
instead.  I do need to iterate over the characters of a string
occasionally, but not often enough to worry about typing a few extra
characters.

> * .chars() doesn't return characters; should it be named something else?

I say leave this one up to Guido.  I'm happy with chars because it
does return characters, as long as we define characters as
length-one-strings. ;-)

> * Should it be a method that is called?

I think this is actually a general question about views.  Should views
be created with methods or properties?  I'm inclined towards the
former, but I think this discussion should be carried out in a
different thread.

> * Are there other views on strings?  Can string->byte encoding be
> usefully seen as a view in some cases?

I refuse to answer this question on the grounds that it may incriminate me. ;-)

STeVe
--
Grammar am for people who can't think for myself.
        --- Bucky Katt, Get Fuzzy


More information about the Python-3000 mailing list