Ok, this is maybe a difficult question. And I don’t want you to do all the hard work for me. I’m just tring to get some good advices and points where I should start.
I’m writing a couple of python programs and i’m having a bad time debugging those. So i’d like to create a simple debug function that records a couple of things.
This is how I’d use it:
# Defined in random_function_definitios.py
def some_random_function():
a = 1 + 1
debug(a)
# More stuff
I’d like to display in debug this information:
- The function that invoked it: some_random_function
- The filename where that function is defined: random_function_definitios.py
- The line number: 4
- Some context: Global variables defined and local variables defined.
I’ve been taking a look at the inspect module and the frame builtin object. But i’m not completely sure if i’m in the right direction.
Thank you!
I wrote my own debugger.py with info / warning and debug messages.
see: https://github.com/unixunion/toolbox/blob/master/python/debugger.py
I also use a traceback to go through the stack like:
Gives results like:
Kegan