On 20 August 2016 at 15:47, Franklin? Lee <leewangzhong+pyt...@gmail.com>
wrote:
On Aug 19, 2016 11:14 PM, "Alexander Heger" <pyt...@2sn.net> wrote:
>
> standard python should discontinue to see strings as iterables of
characters - length-1 strings.  I see this as one of the biggest design
flaws of python.  It may have seem genius at the time, but it has passed it
usefulness for practical language use.

I'm bothered by it whenever I want to write code that takes a sequence and
returns a sequence of the same type.

But I don't think that the answer is to remove the concept of strings as
sequences. And I don't want strings to be sequences of character code
points, because that's forcing humans to think on the implementation level.

Please explain the problem with the status quo, preferably with examples
where it goes wrong.

> For example, numpy has no issues
>
> >>> np.array('abc')
> array('abc', dtype='<U3')

That says, "This is a 0-length array of 3-char Unicode strings." Numpy
doesn't recognize the string as a specification of an array. Try
`np.array(4.)` and you'll get (IIRC) `array(4., dtype='float')`, which has
shape `()`. Numpy probably won't let you index either one. What can you
even do with it? (By the way, notice that the string size is part of the
dtype.)

it is a generalisation of n-dimensional arrays

you can index it using '()'

>>> a = np.array('abc')
>>> a[()]
'abc'
>>> a[()][2]
'c'

The point is it does not try to disassemble it into elements as it would do
with other iterables

>>> np.array([1,2,3])
array([1, 2, 3])
>>> np.array([1,2,3]).shape
(3,)

Numpy is for numbers. It was designed with numbers in mind. Numpy's
relevant experience here is waaaay less than general Python's.

But it does deal with strings as monolithic objects, doing away with many
of the pitfalls of strings in Python.
And yes, it does a lot about memory management, so it is fully aware of
strings and bytes ...
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to