Better tracebacks for exec and execfile
Stefan Franke
franke at ableton.com
Tue Sep 3 08:41:13 EDT 2002
1. I'm toying araound with a text templating engine containing
embedded Python scripts. These scripts are run with exec.
If they throw an exception, the traceback looks like
File "<string>", line 5
e = a+c+b+
^
SyntaxError: invalid syntax
Since the scripts are extracted from a bigger file, the filename
"<string>" and line number are almost useless. Is there a way
to pass both to the interpreter and make them appear in
tracebacks?
2. If a command file passed to execfile throws an exception,
again the traceback looks like this:
File "D:\Programme\Python22\del.py", line 7, in ?
execfile(filename)
File "<string>", line 5
e = a+c+b+
^
SyntaxError: invalid syntax
Why isn't the filename shown instead of "<string>"?
More information about the Python-list
mailing list