from reverse_tb.core import reverse_tb
reverse_tb
reverse_tb is a jupyter notebook magic that reverses the order of the traceback, making it easier to see the most relevant information at the top of the cell output.
Install
pip install reverse_tb
How to use
def foo():
return bar()
def bar():
return baz()
def baz():
try:
qux()except KeyError as e:
raise Exception
return qux()
def qux():
= {}
d return d['key']
foo()
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
2], line 9, in baz()
Cell In[8 try:
----> 9 qux()
10 except KeyError as e:
2], line 16, in qux()
Cell In[15 d = {}
---> 16 return d['key']
KeyError: 'key'
During handling of the above exception, another exception occurred:
Exception Traceback (most recent call last)
3], line 1
Cell In[----> 1 foo()
2], line 2, in foo()
Cell In[1 def foo():
----> 2 return bar()
2], line 5, in bar()
Cell In[4 def bar():
----> 5 return baz()
2], line 11, in baz()
Cell In[9 qux()
10 except KeyError as e:
---> 11 raise Exception
12 return qux()
Exception:
%%reverse_tb
foo()
---------------------------------------------------------------------------
KeyError Traceback (last call first)
KeyError: 'key'
2], line 16, in qux()
Cell In[15 d = {}
---> 16 return d['key']
= {}
d
2], line 9, in baz()
Cell In[8 try:
----> 9 qux()
10 except KeyError as e:
During handling of the above exception, another exception occurred:
Exception Traceback (last call first)
Exception:
2], line 11, in baz()
Cell In[9 qux()
10 except KeyError as e:
---> 11 raise Exception
12 return qux()
2], line 5, in bar()
Cell In[4 def bar():
----> 5 return baz()
2], line 2, in foo()
Cell In[1 def foo():
----> 2 return bar()
4], line 1
Cell In[----> 1 foo()
from reverse_tb.on import *
foo()
---------------------------------------------------------------------------
KeyError Traceback (last call first)
KeyError: 'key'
2], line 16, in qux()
Cell In[15 d = {}
---> 16 return d['key']
= {}
d
2], line 9, in baz()
Cell In[8 try:
----> 9 qux()
10 except KeyError as e:
During handling of the above exception, another exception occurred:
Exception Traceback (last call first)
Exception:
2], line 11, in baz()
Cell In[9 qux()
10 except KeyError as e:
---> 11 raise Exception
12 return qux()
2], line 5, in bar()
Cell In[4 def bar():
----> 5 return baz()
2], line 2, in foo()
Cell In[1 def foo():
----> 2 return bar()
4], line 1
Cell In[----> 1 foo()
reverse_tb_off() foo()
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
2], line 9, in baz()
Cell In[8 try:
----> 9 qux()
10 except KeyError as e:
2], line 16, in qux()
Cell In[15 d = {}
---> 16 return d['key']
KeyError: 'key'
During handling of the above exception, another exception occurred:
Exception Traceback (most recent call last)
3], line 1
Cell In[----> 1 foo()
2], line 2, in foo()
Cell In[1 def foo():
----> 2 return bar()
2], line 5, in bar()
Cell In[4 def bar():
----> 5 return baz()
2], line 11, in baz()
Cell In[9 qux()
10 except KeyError as e:
---> 11 raise Exception
12 return qux()
Exception: