4 ms·
I bloody hate Python stacktraces because they usually don’t have enough information to fix the bug. The curse of dynamic languages. What’s the easiest possible
by forrestthewoods 2y ago
I bloody hate Python stacktraces because they usually don’t have enough information to fix the bug. The curse of dynamic languages.
What’s the easiest possible way to cause stacktraces to also dump local variable information? I feel like this is a feature that should be built into the language…
- aidos 2y agoI love debugging Python. The stacktraces are great when logged through Sentry so even on production I can normally spot the bug immediately. On my local machine it’s even better because I can run the code, let it break and then jump straight into the debugger where I can move up and down through the stack. I can sit in the context at any point and play with the data. I can call any Python function I want to see how the code behaves.
- vanschelven 2y ago> The stacktraces are great when logged through Sentry <cough>Bugsink</cough> :-)
- nomel 2y agoI don't think it's related to being a dynamic language. There are many "pretty exception printers" that will dump all the local and global variables, if you want, even up the stack!
- saila 2y agoI don't think Python is special in this regard. I have the same issue with .NET/C# stack traces. With Python, you can run your program under pdb, which will automatically enter break on exceptions, and you can easily print locals. https://docs.python.org/3/library/pdb.html https://docs.python.org/3/library/pdb.html
- Sohcahtoa82 2y ago> What’s the easiest possible way to cause stacktraces to also dump local variable information? I feel like this is a feature that should be built into the language… That is built into Python! import sys def div(x, y): return x / y try: print(div(1, 0)) except ZeroDivisionError as e: print("Div by zero!") print("Locals:") _, _, tb = sys.exc_info() print(tb.tb_next.tb_frame.f_locals) This will output: Div by zero! Locals: {'x': 1, 'y': 0} https://stackoverflow.com/a/5328139 https://stackoverflow.com/a/5328139 has a more thorough implementation that will print you entire stack of local variables.
- NoGravitas 2y agoI don't think it's intrinsic to dynamic languages. I've been reading this from a Common Lisp perspective and all I can think of is, "look what they need to mimic a fraction of our power".