[Numpy-discussion] fromfile and ticket #1152
Sat Jun 27 14:08:49 CDT 2009
On 2009-06-27, Jed Ludlow <firstname.lastname@example.org> wrote:
> Of course, this discussion isn't new, and I don't know that it needs to be
> completely rehashed. See
I think we sort of converged on some aspects of viable interface
- "Non-strict" interface
Return as many items as can be read, or up to `count`, if given.
Never raise errors or warnings. Stop reading immediately on
fromstring("1,2,x,4", sep=",") -> [1,2]
fromstring("1,2,x,4", sep=",", count=5) -> [1,2]
- Strict interface
Raise ValueError on malformed input, or if there are not
enough items for `count`.
fromstring("1,2,x,4", sep=",") -> ValueError
fromstring("1,2,3,4", sep=",", count=5) -> ValueError
The main disagreement was which of the above to use as the
A hybrid of the above, which would raise an error only when
`count` was specified, was also suggested.
Then some variations on whether default values should be
introduced and what to do with non-numeric entries in this case.
- We should not break backward compatibility, so the "non-strict" interface
should be the default.
No errors or warnings raised, except passing through underlying
I/O errors (eg. sector not found and other OS-level stuff).
- We could optionally, later on, implement the strict interface.
- We should drop the idea of default values for now, and
keep fromfile and fromstring simple.
> I would vote toward harmonizing the behavior with the python built-in
> fid.read(bytes) as the default, which simply returns as many items as could be
> read before the EOF was reached, including zero. An additional strict interface
> could be added (by keyword) for those who want an exception raised whenever the
> requested read count could not be completed.
More information about the Numpy-discussion