Re: [Numpy-discussion] Array and string interoperability

2017-06-05 Thread Chris Barker
Just a few notes: However, the fact that this works for bytestrings on Python 3 is, in my > humble opinion, ridiculous: > > >>> np.array(b'100', 'u1') # b'100' IS NOT TEXT > array(100, dtype=uint8) > Yes, that is a mis-feature -- I think due to bytes and string being the same object in py2 -- so

Re: [Numpy-discussion] Array and string interoperability

2017-06-05 Thread Thomas Jollans
On 05/06/17 19:40, Chris Barker wrote: > > If you ask me, passing a unicode string to fromstring with sep='' > (i.e. > to parse binary data) should ALWAYS raise an error: the semantics only > make sense for strings of bytes. > > > exactly -- we really should have a "frombytes()" ali

Re: [Numpy-discussion] Array and string interoperability

2017-06-05 Thread Chris Barker
On Mon, Jun 5, 2017 at 1:51 PM, Thomas Jollans wrote: > > and overloading fromstring() to mean both "binary dump of data" and > > "parse the text" due to whether the sep argument is set was always a > > bad idea :-( > > > > .. and fromstring(s, sep=a_sep_char) > > As it happens, this is pretty mu

Re: [Numpy-discussion] Array and string interoperability

2017-06-05 Thread Mikhail V
On 4 June 2017 at 23:59, Thomas Jollans wrote: > > > For what it's worth, in Python 3 (which you probably should want to be > using), everything behaves as you'd expect: > import numpy as np s = b'012 abc' a = np.fromstring(s, 'u1') a > array([48, 49, 50, 32, 97, 98, 99], dtype

Re: [Numpy-discussion] Array and string interoperability

2017-06-05 Thread Mikhail V
On 5 June 2017 at 19:40, Chris Barker wrote: > > >> > Python3 assumes 4-byte strings but in reality most of the time >> > we deal with 1-byte strings, so there is huge waste of resources >> > when dealing with 4-bytes. For many serious projects it is just not >> > needed. >> >> That's quite enough