[Numpy-discussion] stderr

Charles R Harris charlesr.harris at gmail.com
Sat Jun 27 15:38:14 EDT 2009

On Sat, Jun 27, 2009 at 1:12 PM, Pauli Virtanen <pav at iki.fi> wrote:

> On 2009-06-27, Charles R Harris <charlesr.harris at gmail.com> wrote:
> [clip]
> >
> >    PyOS_snprintf(format, sizeof(format), _FMT1, prec);
> >    res = NumPyOS_ascii_format at type@(buf, buflen, format, val, 0);
> >    if (res == NULL) {
> >        fprintf(stderr, "Error while formatting\n");
> >        return;
> >    }
> >
> [clip]
> > Do we want to raise an error here? Alternatively, we could use an assert.
> I'd advise against asserts. They should be used only for
> conditions that are (expected to be) logically impossible. This
> one here seems to be possible when out-of-memory, or some other
> condition.
> Also, an assert makes the program crash on C-level, which is
> clearly undesirable in a Python program as it cannot be handled.
> Raising an error here seems to be the proper thing to do.

I'm inclined that way also, but it will require some work. The routine
currently returns nothing so the calling routine will need to call into
python to see if an error was raised. Alternatively, we could add an error

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20090627/1bd6ce14/attachment.html>

More information about the NumPy-Discussion mailing list