[Python-3000] Making strings non-iterable

Aahz aahz at pythoncraft.com
Mon Apr 17 03:36:11 CEST 2006


On Mon, Apr 17, 2006, Greg Ewing wrote:
> Guido van Rossum wrote:
>> 
>> I think you may be right. I implemented this (it was really simple
>> to do) but then found I had to fix tons of places that iterate over
>> strings.
>
> 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.

My post was prompted by a recent dealing with someone who was not a
Python programmer but needed to check strings for punctuation (user-mode
code in a larger app).  After thinking for a bit, the simplest solution
that I could think of for easy explanation was this:

PUNCT = '.,!;'
for char in PUNCT:
    if char in field:
        raise ValueError(char + " not allowed in field")

Anything that would make this solution more difficult to explain would
make my life more difficult.  I know there are many better and more
efficient mechanisms (particularly if one is not restricted to Python
2.2),  but it seems to me that we cannot afford to let Python 3.0 become
the experts' playground.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"LL YR VWL R BLNG T S"


More information about the Python-3000 mailing list