<br><br><div class="gmail_quote">On Sat, May 23, 2009 at 2:02 PM, Christopher Barker <span dir="ltr"><<a href="mailto:Chris.Barker@noaa.gov">Chris.Barker@noaa.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">Stéfan van der Walt wrote:<br>
> 2009/5/23 Charles R Harris <<a href="mailto:charlesr.harris@gmail.com">charlesr.harris@gmail.com</a>>:<br>
>> In [9]: fromfile("empty.dat", count=10)<br>
<br>
</div><div class="im">> Instead of throwing errors in these scenarios, we could just return<br>
> the elements read and raise a warning? This is consistent with most<br>
> other file APIs I know and allows you to read blocks of data until the<br>
> data runs out.<br>
<br>
</div>This was just discussed a week or two ago (look for messaged by me and<br>
Robert Kern)<br>
<br>
fromfile needs some attention in general, but I think Robert an I (the<br>
only two that I know were paying attention to that discussion) agreed<br>
that there should be an API that says:<br>
<br>
read up to n items from the file<br>
<br>
Robert thought that should be the default, but I think that means<br>
everyone would be forced to check how many items they got every time<br>
they read, which is too much code and likely to be forgotten and lead to<br>
errors. So I think that an exception should be raised if you ask for n<br>
and get less than n, but that there should be a flag that says something<br>
like "max_items=n", that indicates that you'll take what you get.<br>
<br>
I don't like a warning -- it's unconventional to catch those like<br>
exceptions -- if you want n items, and you haven't written code to<br>
handle less than n, you should get an exception. If you have written<br>
code to handle that, that you can use the flag.<br>
</blockquote><div><br>I don't like the idea of a warning here either. How about adding a keyword 'strict' so that strict=1 means an error is raised if the count isn't reached, and strict=0 means any count is acceptable?<br>
<br>Chuck <br></div></div><br>