When error occured Python prints something like this:
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "<stdin>", line 8, in m
File "<stdin>", line 5, in exec_st
File "<stdin>", line 9, in exec_assign
File "<stdin>", line 48, in ref_by_id
IndexError: list index out of range
where 2, … , 48 are relative line numbers which are not very convenient. How to print absolute line numbers in such error messages?
EDIT:
Maybe it’s a dumb question, but answer will facilitate development a little.
I’m printing text in several files. When done, press shortcut which runs python and copies contents of current file to console. Proposed solution forces to press excess keystrokes (Ctrl+S, Alt+Tab) and create additional files. I hope I have put it clear.
A few minutes of hacking around gives me this Read-Eval-Print Loop in Python 2.7:
It’s a bit hackish, but it keeps track of line numbers as the session continues, and allows the current count to be reset by a call to
reset_linenum(). An example session:EDIT: Fixed REPL to not execute indented blocks quite so prematurely.