<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Jun 5, 2017 at 1:51 PM, Thomas Jollans <span dir="ltr"><<a href="mailto:tjol@tjol.eu" target="_blank">tjol@tjol.eu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">> and overloading fromstring() to mean both "binary dump of data" and<br>
> "parse the text" due to whether the sep argument is set was always a<br>
> bad idea :-(<br>
><br>
> .. and fromstring(s, sep=a_sep_char)<br>
<br>
</span>As it happens, this is pretty much what stdlib bytearray does since 3.2<br>
(<a href="http://bugs.python.org/issue8990" rel="noreferrer" target="_blank">http://bugs.python.org/<wbr>issue8990</a>)</blockquote><div><br></div><div>I'm not sure that the array.array.fromstring() ever parsed the data string as text, did it?</div><div><br></div><div>Anyway, This is what array.array now has:</div><div><dl class="gmail-method" style="margin-bottom:15px"><font face="monospace, monospace">array.frombytes(s)<br></font></dl></div></div></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div class="gmail_extra"><div class="gmail_quote"><div><dl class="gmail-method" style="margin-bottom:15px"><font face="monospace, monospace">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).</font></dl></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><dl class="gmail-method" style="margin-bottom:15px"><font face="monospace, monospace">New in version 3.2: fromstring() is renamed to frombytes() for clarity.</font></dl></div></div></div></blockquote><span style="font-family:monospace,monospace">array.fromfile(f, n)</span><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div class="gmail_extra"><div class="gmail_quote"><div><dl class="gmail-method" style="margin-bottom:15px"><font face="monospace, monospace">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.</font></dl></div></div></div></blockquote><div class="gmail_extra"><div class="gmail_quote"><div><dl class="gmail-method" style="margin-bottom:15px"><font face="monospace, monospace">array.fromstring()<br></font></dl></div></div></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div class="gmail_extra"><div class="gmail_quote"><div><dl class="gmail-method" style="margin-bottom:15px"><font face="monospace, monospace">Deprecated alias for frombytes().</font></dl></div></div></div></blockquote><div class="gmail_extra"><div class="gmail_quote"><div><dl class="gmail-method" style="margin-bottom:15px">I think numpy should do the same.</dl><dl class="gmail-method" style="margin-bottom:15px">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???</dl><dl class="gmail-method" style="margin-bottom:15px">And the fromfile() sep argument should be deprecated as well, for the same reasons.</dl><dl class="gmail-method" style="margin-bottom:15px">array also has:<br><br><font face="monospace, monospace">array.fromunicode(s)<br></font></dl></div></div></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div class="gmail_extra"><div class="gmail_quote"><div><dl class="gmail-method" style="margin-bottom:15px"><font face="monospace, monospace">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.</font></dl></div></div></div></blockquote><div class="gmail_extra"><div class="gmail_quote"><div><dl class="gmail-method" style="margin-bottom:15px">which I think would be better supported by:</dl><dl class="gmail-method" style="margin-bottom:15px"><font face="monospace, monospace">np.frombytes(str.encode('UCS-4'), dtype=uint32)<br></font></dl></div></div><div>-CHB</div><div><br></div><div><br></div>-- <br><div class="gmail_signature"><br>Christopher Barker, Ph.D.<br>Oceanographer<br><br>Emergency Response Division<br>NOAA/NOS/OR&R            (206) 526-6959   voice<br>7600 Sand Point Way NE   (206) 526-6329   fax<br>Seattle, WA  98115       (206) 526-6317   main reception<br><br><a href="mailto:Chris.Barker@noaa.gov" target="_blank">Chris.Barker@noaa.gov</a></div>
</div></div>