ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 20 May 2019 18:59:40 +0200How to recreate traceback?https://ask.sagemath.org/question/46565/how-to-recreate-traceback/Hello, Sage Community.
When we write something like `sin(t)` without previously defining the variable `t`, we get a traceback like
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-138-17829414d33a> in <module>()
----> 1 sin(t)
NameError: name 't' is not defined
I would like to reproduce this text automatically. I have tried the following:
try:
sin(t)
except:
_typ_, _val_, _tb_ = sys.exc_info()
traceback.print_exception(_typ_, _val_, _tb_)
However, this produces a less rich output:
Traceback (most recent call last):
File "<ipython-input-139-55b9ce98509c>", line 2, in <module>
sin(t)
NameError: name 't' is not defined
How could I reproduce the rich output?
Thanks in advance for your answers!Fri, 17 May 2019 21:58:18 +0200https://ask.sagemath.org/question/46565/how-to-recreate-traceback/Answer by nbruin for <p>Hello, Sage Community.</p>
<p>When we write something like <code>sin(t)</code> without previously defining the variable <code>t</code>, we get a traceback like</p>
<pre><code>---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-138-17829414d33a> in <module>()
----> 1 sin(t)
NameError: name 't' is not defined
</code></pre>
<p>I would like to reproduce this text automatically. I have tried the following:</p>
<pre><code>try:
sin(t)
except:
_typ_, _val_, _tb_ = sys.exc_info()
traceback.print_exception(_typ_, _val_, _tb_)
</code></pre>
<p>However, this produces a less rich output:</p>
<pre><code>Traceback (most recent call last):
File "<ipython-input-139-55b9ce98509c>", line 2, in <module>
sin(t)
NameError: name 't' is not defined
</code></pre>
<p>How could I reproduce the rich output?</p>
<p>Thanks in advance for your answers!</p>
https://ask.sagemath.org/question/46565/how-to-recreate-traceback/?answer=46572#post-id-46572You should probably look at IPython.core.ultratb . It looks like that's the part of IPython that produces the colourful tracebacks.Sat, 18 May 2019 09:28:57 +0200https://ask.sagemath.org/question/46565/how-to-recreate-traceback/?answer=46572#post-id-46572Comment by dsejas for <p>You should probably look at IPython.core.ultratb . It looks like that's the part of IPython that produces the colourful tracebacks.</p>
https://ask.sagemath.org/question/46565/how-to-recreate-traceback/?comment=46594#post-id-46594Thank you very much, @nbruin! Indeed, IPython.core.ultratb was the correct way to proceed. I have also found sage.interacts.debugger, which has similar functionality, but is a little restricted in comparison.Mon, 20 May 2019 18:59:40 +0200https://ask.sagemath.org/question/46565/how-to-recreate-traceback/?comment=46594#post-id-46594