How to extract complete file path from traceback info

Peter Hansen peter at engcorp.com
Fri Jun 18 21:31:30 EDT 2004


Kenneth McDonald wrote:

> I have a need to customize the output of Python error tracebacks,
> and to that end I've implemented my own sys.excepthook function.
> However, one remaining problem that I'm having is the information
> passed to this function doesn't seem to have the _full_ path name
> of the file in which the exception occurred. I need this because
> the output is being parsed by an editor (jEdit) which uses this
> information to set up links to errors origins in the source
> code.
> 
> Is there an easy way to get this info somehow? (I haven't been
> able to find it.) I can think of some 'solutions' I'd prefer
> not to attempt unless I have to.

Searching the source for the traceback module, I saw that it
calls code in the linecache module which apparently has to
do a manual search down the sys.path to find the files that
are imported...  that probably means (a) there is no other
way to do it, (b) there's example code for you in linecache.py,
and (c) it might have some troubles with the new zip-file
based imports etc... (not that that would be a particular
problem in your case, but it could confuse things).

-Peter



More information about the Python-list mailing list