
On Tue, Aug 28, 2012 at 6:26 PM, Mike Graham mikegraham@gmail.com wrote:
It's possible to give a lot more on error than the default traceback gives you. I propose that Python should ship a more verbose formatter and a command line switch to use it.
Here's an example of IPython's verbose formatter. I wrote a buggy program:
def f(a): x = a * 4 y = a - 4 return x / y
def main(): for i in xrange(100): f(i)
main()
and then ran it in IPython with verbose tracebacks and got the following output:
ZeroDivisionError Traceback (most recent call last)
/home/mike/foo.py in <module>() 8 f(i) 9 ---> 10 main() global main = <function main at 0x10bd7d0> 11 12
/home/mike/foo.py in main() 6 def main(): 7 for i in xrange(100): ----> 8 f(i) global f = <function f at 0x10bd758> i = 4 9 10 main()
/home/mike/foo.py in f(a=4) 2 x = a * 4 3 y = a - 4 ----> 4 return x / y x = 16 y = 0 5 6 def main():
ZeroDivisionError: integer division or modulo by zero
This is very handy! The reprs of all locals are input so I can see what the values of a, x, and y were when I had my error and there are a few lines of code on either side of the line that matters to help me get oriented. The former feature is the more powerful one, although enabling this by default is a bad idea; (first and foremost, this can be a security hazard). I can't count how many trips into pdb this would have saved me.
I think having this feature be part of Python itself would be very helpful to new learners and to those helping them. I constantly deal with learners seeking help who are unable to clearly provide the actual values and types of the objects in the code they're having trouble with; it would be nice simply to say, "Show me a verbose traceback" and might even help them to debug their code without assistance.
+1 on the more verbose formatter in stdlib
Rather than a glad, I'd like to see the path to a formatter, so you can use more than just the two builtin. It would be great to easily define my own and have that used in all cases.
python -t traceback.VerboseFormatter my_broken_script.py
Mike _______________________________________________ Python-ideas mailing list Python-ideas@python.org http://mail.python.org/mailman/listinfo/python-ideas