For debugging/logging purposes, I would like to write the full stack to a file (such as in this question). I can do this using traceback.format_stack()
. However, I would like it to look like the more verbose tracebacks that IPython
outputs, for example, formatting with IPython.core.ultratb.VerboseTB
.
It appears the classes and methods in IPython.core.ultratb
require information on exceptions, as they are designed for tracebacks. But I have no exception: I just want to display the stack in a verbose way.
How can I use the output methods of IPython.core.ultratb.VerboseTB
to format the stack such as reported by traceback.extract_stack()
or inspect.stack()
?
ltratb.VerboseTB()(etb=traceback.extract_stack())
– FlavescentAttributeError: 'StackSummary' object has no attribute 'tb_frame'
(ininspect.getinnerframes
) andTypeError: 'NoneType' object is not iterable
(inultratb.VerboseTB.format_records
). I'm not sure why I get two exceptions (with tracebacks) for a single expression, but I do. – Kilohertzprint_tb
(disclaimer: I wrote that). – Retortion