[Python-Dev] OOps (was: No 1.6! (was Re: A REALLY COOL PYTHON FEATURE:))
Thu, 18 May 2000 00:34:13 -0400
> Then a string should better not be a sequence.
> The number of places where I really used the string sequence
> protocol to take advantage of it is outperfomed by a factor
> of ten by cases where I missed to tupleise and got a bad
> result. A traceback is better than a sequence here.
Alas, I think
for ch in string:
muck w/ the character ch
is a common idiom.
> oh-what-did-I-say-here--duck--but-isn't-it-so--cover-ly y'rs - chris
The "sequenenceness" of strings does get in the way often enough. Strings
have the amazing property that, since characters are also strings,
string = string
never terminates with an error. This often manifests as unbounded recursion
in generic functions that crawl over nested sequences (the first time you
code one of these, you try to stop the recursion on a "is it a sequence?"
test, and then someone passes in something containing a string and it
descends forever). And we also have that
format % values
requires "values" to be specifically a tuple rather than any old sequence,
else the current
"%s" % some_string
could be interpreted the wrong way.
There may be some hope in that the "for/in" protocol is now conflated with
the __getitem__ protocol, so if Python grows a more general iteration
protocol, perhaps we could back away from the sequenceness of strings
without harming "for" iteration over the characters ...