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

Robert Kern robert.kern at gmail.com
Mon May 11 18:52:01 EDT 2009


On Mon, May 11, 2009 at 17:48, Christopher Barker <Chris.Barker at noaa.gov> wrote:
>
> Robert Kern wrote:
>> But that doesn't let you express, "read at most this number of items,"
>> which is really useful and is very common in file-reading APIs.
>
> fair enough --
>
>>> maybe a flag?
>
>> If it makes you feel better, you may consider the warnings mechanism
>> to be just such a flag, only it uses a Python-standard mechanism for
>> controlling such behavior.
>
> no, it doesn't -- I don't think warnings are designed for this sort of
> thing.
>
>>>> This lets you either silence
>>>> the warning or turn it into an exception depending on your use case.
>
> I've been a pythonista for years, and I have no idea how to turn a
> warning into an exception, and I DID just spend some time trying to
> figure it out -- it does not look easy. Maybe it is, but if it's hard to
> figure out, and it won't dawn on many users that they need to, there
> will be bugs.

http://docs.python.org/library/warnings#the-warnings-filter

import warnings
warnings.simplefilter('error', NotEnoughBytesWarning)

> I think we agree that fromfile() needs a way to spell:
>
> "read at most this number of items,"
>
> Why not spell that explicitly? we have "count" to specify whether or not
> you want a specific number of items. We could have max_count or
> whatever. I don't care how it's spelled but I do want to be able to
> explicitly spell which I want.
>
> In any case, having the warning printed with C stdout is not ideal.

Yes.

-- 
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