<p dir="ltr">On 17 May 2013 14:17, "Neal Becker" <<a href="mailto:ndbecker2@gmail.com">ndbecker2@gmail.com</a>> wrote:<br>
><br>
> Nathaniel Smith wrote:<br>
><br>
> > On 16 May 2013 19:48, "Jonathan Helmus" <<a href="mailto:jjhelmus@gmail.com">jjhelmus@gmail.com</a>> wrote:<br>
> >><br>
> >> On 05/16/2013 01:42 PM, Neal Becker wrote:<br>
> >> > Is there a way to get a traceback instead of just printing the<br>
> >> > line that triggered the error?<br>
> >> ><br>
> >> > _______________________________________________<br>
> >> > NumPy-Discussion mailing list<br>
> >> > <a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
> >> > <a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
> >> Neal,<br>
> >><br>
> >>      Look at the numpy.seterr function.  You can use it to change how<br>
> >> floating-point errors are handled, including raising a<br>
> >> FloatingPointError with a traceback as opposed to printing a<br>
> >> RuntimeWarning.<br>
> >><br>
> >> Example<br>
> >><br>
> >> $ cat foo.py<br>
> >> import numpy as np<br>
> >><br>
> >> np.seterr(divide='raise')<br>
> >><br>
> >> a = np.array([1,1,1], dtype='float32')<br>
> >> a / 0<br>
> >><br>
> >> $ python foo.py<br>
> >> Traceback (most recent call last):<br>
> >>    File "test.py", line 6, in <module><br>
> >>      a / 0<br>
> >> FloatingPointError: divide by zero encountered in divide<br>
> ><br>
> > You also have the option of using Python's general ability to customize how<br>
> > any warning is handled - see the 'warnings' module and -W switch.<br>
> ><br>
> > If you just want a traceback printed without an exception then I think you<br>
> > can do that with np.seterr too (using np.seterrcall).<br>
> ><br>
> > -n<br>
><br>
> I tried this:<br>
><br>
> import traceback<br>
><br>
> np.seterrcall (lambda a,b: traceback.print_stack)<br>
> np.seterr (all='call')</p>
<p dir="ltr">Try adding some parens?</p>
<p dir="ltr"> np.seterrcall (lambda a,b: traceback.print_stack())</p>
<p dir="ltr">-n</p>