[Python-3000] Making strings non-iterable

Tim Peters tim.peters at gmail.com
Mon Apr 17 05:25:12 CEST 2006


[Guido]
>> ...
>> I implemented this (it was really simple to do) but then found I had
>> to fix tons of places that iterate over strings.

[Greg Ewing]
> I wonder if the stdlib might be a bit unusual here,
> since it's the place where low-level things are
> implemented. I don't think there would be many places
> in my code that would be affected, but others'
> experiences may be different.

I expect it depends on whether someone writes text-processing
algorithms.  If you do, it's quite natural to iterate over strings.  I
have lots of code doing that, although I had no objection to needing
to ask for a view in order to iterate, so didn't object to the
proposal.

Now that I think of it, though, I've been burned perhaps twice in my
total Python life by recursing on a string when I didn't intend to. 
Apart from flatten()-ish functions, I'm not sure I've written anything
vulnerable to that.

The only example of "a trap" I noticed in this thread was:

"""
Seeing this:

<ul>
 <li> i
 <li> t
 <li> e
 <li> m
 <li>
 <li> 1
</ul>

a few too many times... it's annoying.
"""

But I've never seen that, and didn't see the connection to strings
being iterable.  I'm sure some careless web code somewhere does that,
though ;-)


More information about the Python-3000 mailing list