On Mon, Jun 5, 2017 at 1:51 PM, Thomas Jollans <[email protected]> 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
> (http://bugs.python.org/issue8990)
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:
array.frombytes(s)
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
fromfile()method).
New in version 3.2: fromstring() is renamed to frombytes() for clarity.
array.fromfile(f, n)
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.
array.fromstring()
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:
array.fromunicode(s)
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'),
dtype=uint32)
-CHB
--
Christopher Barker, Ph.D.
Oceanographer
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
[email protected]
_______________________________________________
NumPy-Discussion mailing list
[email protected]
https://mail.python.org/mailman/listinfo/numpy-discussion