Sebastian Berg wrote:

> However, in the same code, often strings are actually not desired to be
> handled as sequences.
> I.e. some code uses strings as sequences of characters, but most code
> probably uses the meaning that a string is a word, or sentence: the
> individual character has no useful meaning on its own.

Humm... It is not a matter of how often. It about the underlying type of 
strings and the derived behaviour. In Python, they are immutable sequences of 
characters. It does matter if you use them as characters, as words, as 
bibles... If you have a list of integers, does it behave differently if it 
contains a few countries' GDP, the songs in each Metallica's LPs, or the first 
two hundred primes? No, it does not. It is a list, a sequence, and you can deal 
with that list in the same ways as you can deal with a string sequence. Because 
they are both collections. This is fine in most cases and I like to know when 
it is not.


> you make it a property rather than a function, you could think about
> also forcing string.chars[0] in the first case.


And once again... which is the superiority of strings.chars[0] over strings[0]? 
Maybe I am dumb, but I can see the difference.


> Coming from NumPy, there is a  subtle spectrum:
> 
> strings are primarily scalars for which sequence behaviour
> is well defined and often convenient
> lists/tuples are typical collections/sequences
> NumPy arrays are more element focused than most collections
> (operators modify the elements not the container).
> 

Nice point. However, we are talking about Python, not NumPy. A nice solution 
for NumPy is not necessary a good one for Python.

You can list lots of languages and libraries which do differently than Python 
but... it does not matter! The question is different: is it right that Python 
string are immutable sequences or not? Should we change this or not?

Sorry, but to the date, I do not see any (Python) example that proves that 
Python strings need a change like this. We can discuss endless about strings 
nature and essence but, in my opinion, we need to focus on real code, on real 
flaws.


Thank for your comments.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/PE7Y4NNBVVNCF3KODF364RQGDCJG2EWG/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to