Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do python exceptions typically not print offending values?

For instance, consider the case:

>>> a = []
>>> a[12]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: list index out of range

the exception does not print the value that was out of range.

My guess is that we don't know if the __str__ function of whatever was passed in raises an exception, so we don't touch it?

like image 578
alexgolec Avatar asked Mar 13 '12 19:03

alexgolec


1 Answers

The value could be printed, it just isn't.

However, there is a tb module on PyPI that actually will print the values of the variables in the stack trace.

like image 135
Ethan Furman Avatar answered Oct 22 '22 10:10

Ethan Furman