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

Robert Kern robert.kern at gmail.com
Mon May 11 15:18:44 EDT 2009


On Mon, May 11, 2009 at 13:43, Christopher Barker <Chris.Barker at noaa.gov> wrote:
> Pauli Virtanen wrote:
>> Fromstring raises "ValueError: string is smaller than requested size" if
>> the string is too short to contain the requested data. Should fromfile do
>> the same,
>
> yes. Or some other exception.
>
>> or do we want to just raise a warning and return fewer items?
>
> maybe, but I don't like that -- you'd have to write code to catch it.
>
>> Or maybe only return fewer items, without a warning?
>
> absolutely not! Then we'd all have to write code to check the result
> every time -- yech!

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.

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

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco



More information about the SciPy-User mailing list