3 ms·
Some self advertisement: I implemented some very similar Python module a while ago (more than 9 years ago actually, but updated all the time): better_exchook:
by albertzeyer 6y ago
Some self advertisement: I implemented some very similar Python module a while ago (more than 9 years ago actually, but updated all the time):
better_exchook: https://pypi.org/project/better-exchook/ https://pypi.org/project/better-exchook/ / https://github.com/albertz/py_better_exchook https://github.com/albertz/py_better_exchook
It's just a single file, so you can easily copy it into your project.
It's a bit more advanced than this as well, as it has some further logic about what variables it actually shows:
* It shows only those which are used in the statement of the active line. In bigger functions, you often have other unrelated locals, and this would become incredibly spammy otherwise. Also, the use locals in the current line are almost always exactly those you are interested in.
* It also shows globals (this one only shows locals).
Like the original traceback and this one, it shows the current active line, and not the context around (e.g. like in IPython or stackprinter).
However, it has an extension: If the current statement goes over multiple lines, it will print them as well.
It also has an extension for DomTerm that you can fold away the variables.