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

spir denis.spir at gmail.com
Mon Jan 6 13:34:01 CET 2014


On 01/05/2014 06:49 PM, Eric Snow wrote:
> On Jan 5, 2014 4:10 AM, "David Townshend" <aquavitae69 at gmail.com> wrote:
>>
>> 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.
>
> Sometimes I think it would be more clear if strings weren't sequences but
> had various attributes that exposed sequence "views", e.g. codepoints,
> etc.  Making strings non-sequences isn't realistic at this point, but
> adding the sequence view attributes may still be nice.
>
> That said, at present it's not something I personally have any use case
> for.  There was an article floating around the web recently where the
> deficiencies of unicode implementations was discussed and I recall
> something there or in related discussions about use cases for having
> different views into a string.  Wow that was vague. :)  The different views
> into unicode strings certainly comes up from time to time on our lists.

This does not fit the picture as long as strings are indexable and sliceable, in 
my opinion.

But most importantly, from the user practice & experience perspective, and while 
from a theoretical one it may be debattable, I consider it a great feature of 
python that everyday "mondane" string processing can be done using simple and 
easy Python string routines (i include here indexing & slicing). Alternatives 
would be regexes (read: Perl) and/or matching/parsing/searching libs (eg 
pyparsing) everywhere in python code; both are difficult, error-prone, hard to 
debug. The former are plain esoteric (but terribly practicle ;-), and I'm happy 
to rarely have to decipher *others'* regexes when reading python code (my own 
are far easier, indeed ;-).

Denis


More information about the Python-ideas mailing list