From: dnagata at creo.com (Dale Nagata)
Date: Sun, 11 Apr 1999 10:42:24 -0700
Subject: bug or feature? traceback with python -x off by one line
Message-ID: <3710DF00.DF5@creo.com>
Content-Length: 2152
X-UID: 613                                                  

I'm using Python 1.5.1 on Windows NT 4.0 Service Pack 3.

If I run a script the "normal" way, the exception
traceback prints the correct source file line numbers:

E:\home\dale\test\>python testx.py
Traceback (innermost last):
  File "E:\home\dale\test\testx.py", line 18, in ?
    main()
  File "E:\home\dale\test\testx.py", line 14, in main
    f = open( 'foo.txt', 'r' )
IOError: (2, 'No such file or directory')

However, if I run the exact same script with the Python -x 
command line option to skip the first line of the script, the
reported line numbers are consistently off by one:

E:\home\dale\test>python -x testx.py
Traceback (innermost last):
  File "testx.py", line 17, in ?
    try:
  File "testx.py", line 13, in main
    def main():
IOError: (2, 'No such file or directory')

Is this the way it's *supposed* to work?

I package a lot of Python scripts as ready-to-run Windows NT batch
files by prepending the line

	@python -x %~f0 %* & goto :EOF

which means "without echoing to the console window, run Python
with the -x option, passing it the full path to this batch file
with the rest of the commmand line arguments, and after it
finishes executing, jump to the end of the batch file so it
doesn't try to interpret the remainder of the file as native NT 
batch language".

So when an error occurs in one of these Python-scripts-disguised-
as-NT-batch-files, the traceback line numbers are always off by
one.
 
I've seen this enough times now that if I'm not too lazy or tired,
I can grudgingly remember to adjust the line numbers, but since 
I've managed to convince a growing number of co-workers to start 
using Python and indeed make it an essential part of our software 
development, it's becoming an increasing source of confusion.

Any ideas on the best way to resolve this?
How, from within a script, can I detect that the -x option is
in effect? Or do I have to go hack the interpreter source?

Thanks in advance,


--
Dale Nagata         |  tel : +1 604.451.2700 ext. 2254 (UTC-0800)
Software Developer  |  fax : +1 604.437.9891 
Creo Products Inc.  |  pgr : +1 604.691.8279
Burnaby BC Canada   |  http://www.creo.com/




