[Numpy-discussion] major bug in fromstring, ascii mode
Charles R Harris
Sun Jan 27 16:43:41 CST 2008
On Jan 27, 2008 3:19 PM, Pauli Virtanen <email@example.com> wrote:
> su, 2008-01-27 kello 13:48 -0700, Charles R Harris kirjoitti:
> > I don't think the problem is scanf, at least not here. The following
> code snippet works fine for me.
> Reading the code in arraytypes.inc.src and multiarraymodule.c, it
> appears that numpy is using strtol(str, &tailptr, 0) for the string to
> integer conversion. Calling strtol with BASE == 0 enables the automatic
> base detection from the prefix.
> However, as you say, scanf does not do this. Numpy appears to use fscanf
> when reading data from files, so there is a discrepancy here:
> >>> from numpy import fromfile, fromstring
> >>> f = open('test.dat', 'w')
> >>> f.write("20:09:21")
> >>> f.close()
> >>> fromfile('test.dat', dtype=int, sep=':')
> array([20, 9, 21])
> >>> fromstring('20:09:21', dtype=int, sep=':')
> array([20, 0])
I vote for fromstring working like fromfile.
> Also, the following result is quite strange, seems like a silent
> >>> fromfile('test.dat', dtype=int)
> array([809119794, 825375289])
The default is to treat the file as containing binary data.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion