[Numpy-discussion] stderr

Pauli Virtanen pav@iki...
Sat Jun 27 14:12:33 CDT 2009

On 2009-06-27, Charles R Harris <charlesr.harris@gmail.com> wrote:
>    PyOS_snprintf(format, sizeof(format), _FMT1, prec);
>    res = NumPyOS_ascii_format@type@(buf, buflen, format, val, 0);
>    if (res == NULL) {
>        fprintf(stderr, "Error while formatting\n");
>        return;
>    }
> 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 

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.

Pauli Virtanen

More information about the Numpy-discussion mailing list