[SciPy-user] fromfile, item, what other output than stdout / stderr is used ?

Christopher Barker Chris.Barker@noaa....
Mon May 11 14:57:58 CDT 2009

Robert Kern wrote:
> There is a long history of returning what bytes you can without
> raising an error. This helps a lot when writing code that reads a
> chunk at a time. E.g. file.read(nbytes) will return nbytes or fewer if
> you get within nbytes of the end of the file.

maybe so, but fromfile() already supports "read 'till the end of the 
file", if you don't know how many items you have.

maybe a flag? I'm still convinced that we're setting up the users for 
bugs if they get fewer items than expected and don't get an exception. I 
see fromfile() as fundamentally higher level than file.read().

> I suggest using the warnings mechanism. This lets you either silence
> the warning or turn it into an exception depending on your use case.

The other question is what gets returned, I'm pretty sure that when you 
call fromfile() with a count, it pre-allocates the array, then fills it, 
so if you don't have enough items in your file, you'll get an array that 
is the size you expect, but with partially junk in it -- another way to 
ask for bugs.


Christopher Barker, Ph.D.

Emergency Response Division
NOAA/NOS/OR&R            (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 SciPy-user mailing list