[Numpy-discussion] Inconsistent error messages.
Sat May 23 15:02:04 CDT 2009
Stéfan van der Walt wrote:
> 2009/5/23 Charles R Harris <firstname.lastname@example.org>:
>> In : fromfile("empty.dat", count=10)
> Instead of throwing errors in these scenarios, we could just return
> the elements read and raise a warning? This is consistent with most
> other file APIs I know and allows you to read blocks of data until the
> data runs out.
This was just discussed a week or two ago (look for messaged by me and
fromfile needs some attention in general, but I think Robert an I (the
only two that I know were paying attention to that discussion) agreed
that there should be an API that says:
read up to n items from the file
Robert thought that should be the default, but I think that means
everyone would be forced to check how many items they got every time
they read, which is too much code and likely to be forgotten and lead to
errors. So I think that an exception should be raised if you ask for n
and get less than n, but that there should be a flag that says something
like "max_items=n", that indicates that you'll take what you get.
I don't like a warning -- it's unconventional to catch those like
exceptions -- if you want n items, and you haven't written code to
handle less than n, you should get an exception. If you have written
code to handle that, that you can use the flag.
Christopher Barker, Ph.D.
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
More information about the Numpy-discussion