[Numpy-discussion] Array and string interoperability
chris.barker at noaa.gov
Mon Jun 5 18:51:11 EDT 2017
On Mon, Jun 5, 2017 at 1:51 PM, Thomas Jollans <tjol at tjol.eu> 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 much what stdlib bytearray does since 3.2
I'm not sure that the array.array.fromstring() ever parsed the data string
as text, did it?
Anyway, This is what array.array now has:
Appends items from the string, interpreting the string as an array of
machine values (as if it had been read from a file using the
New in version 3.2: fromstring() is renamed to frombytes() for clarity.
Read n items (as machine values) from the file object f and append them to
the end of the array. If less than n items are available, EOFError is
raised, but the items that were available are still inserted into the
array. f must be a real built-in file object; something else with a read()
method won’t do.
Deprecated alias for frombytes().
I think numpy should do the same.And frombytes() should remove the "sep"
parameter. If someone wants to write a fast efficient simple text parser,
then it should get a new name: fromtext() maybe???And the fromfile() sep
argument should be deprecated as well, for the same reasons.array also has:
Extends this array with data from the given unicode string. The array must
be a type 'u' array; otherwise a ValueError is raised.
Usearray.frombytes(unicodestring.encode(enc)) to append Unicode data to an
array of some other type.
which I think would be better supported by:np.frombytes(str.encode('UCS-4'),
Christopher Barker, Ph.D.
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion