[Python-ideas] str.startswith taking any iterator instead of just tuple

David Townshend aquavitae69 at gmail.com
Sun Jan 5 12:09:38 CET 2014


Reading this thread made me start to think about why a string is a
sequence, and I can't actually see any obvious reason, other than
historical ones. Every use case I can think of for iterating over a string
either involves first splitting the string, or would be better done with a
regex. Also, the only times I can recall using a string as a sequence is in
doctests (because it reads better than a list of characters) or in the
interpreter when I'm trying something out. I'm not suggesting changing it -
there's too much history for that, but I am interested to know if there is
some fundamental reason that strings are sequences. If a new string object
was being implemented now, would it be a sequence?
On 3 Jan 2014 02:49, "Guido van Rossum" <guido at python.org> wrote:

> By designing an API that doesn't require such overloading.
>
> On Thursday, January 2, 2014, Alexander Heger wrote:
>
>> >>    isinstance(x, Iterable) and not isinstance(x, str)
>> >
>> > If you find yourself typing that a lot I think you have a bigger
>> problem though.
>>
>> How do you replace this?
>> _______________________________________________
>> Python-ideas mailing list
>> Python-ideas at python.org
>> https://mail.python.org/mailman/listinfo/python-ideas
>> Code of Conduct: http://python.org/psf/codeofconduct/
>>
>
>
> --
> --Guido van Rossum (on iPad)
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140105/bb7f6196/attachment.html>


More information about the Python-ideas mailing list