including column information when an exception occurs

Terry Reedy tjreedy at udel.edu
Sat Dec 4 17:41:14 EST 1999


To get line numbers in tracebacks, line numbers must be compiled into 
the Pycode.  This makes the result a bit longer than it would otherwise 
be, but more useful when we goof.  Given that the source is read a line 
at a time, or that '\n' must be special-cased anyway, this is easily 
done.

Adding column numbers would make compilation and execution time and 
bytecode space even more.  Improving messages is probably a better 
direction to go (such as  giving the out-of-range index).  I believe 
this is in progress.

TJR

In article <384957FA.164010A6 at mikemccandless.com>, 
mail at mikemccandless.com says...


>When a Python exception occurs, the interpreter shows you the stack
>traceback to the line where the error occurred.  Why, when it gets down
>to the actual line, does it not also report, eg, the column or
>subexpression in which the error occurs?

>This would be useful when you have lines that have a fair number of
>operations such that the exception could have come from more than one
>sub-expression.

>EG, in the following program:

>  def test0(tup, i0, i1):
>    test1(tup, i0, i1)

>  def test1(tup, i0, i1):
>    return tup[i0] + tup[i1]

>  test0((1, 2, 3), 2, 4)

>This exception is generated:

>  Traceback (innermost last):
>    File "test2.py", line 7, in ?
>      test0((1, 2, 3), 2, 4)
>    File "test2.py", line 2, in test0
>      test1(tup, i0, i1)
>    File "test2.py", line 5, in test1
>      return tup[i0] + tup[i1]
>  IndexError: tuple index out of range

>But, it's unclear which tuple reference caused the IndexError...

>Mike





More information about the Python-list mailing list