How to extract complete file path from traceback info

Discussion in 'Python' started by Kenneth McDonald, Jun 18, 2004.

  1. 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.

    Thanks,
    Ken McDonald
     
    Kenneth McDonald, Jun 18, 2004
    #1
    1. Advertising

  2. Kenneth McDonald

    Peter Hansen Guest

    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
     
    Peter Hansen, Jun 19, 2004
    #2
    1. Advertising

  3. Am Fri, 18 Jun 2004 21:31:03 +0000 schrieb Kenneth McDonald:

    > 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.


    Hi Kenneth,

    AFAIK, the module cgitb does this. Take a look at it.

    HTH,
    Thomas
     
    Thomas Guettler, Jun 21, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mupota Muchelemba
    Replies:
    1
    Views:
    919
    Tony Morris
    Feb 4, 2004
  2. Jan Decaluwe
    Replies:
    0
    Views:
    312
    Jan Decaluwe
    Nov 7, 2003
  3. Duncan Booth

    Using Python traceback info from C/C++.

    Duncan Booth, Jul 12, 2004, in forum: Python
    Replies:
    1
    Views:
    1,943
    Jeff Holle
    Jul 12, 2004
  4. R. Bernstein
    Replies:
    8
    Views:
    399
    R. Bernstein
    Jan 16, 2006
  5. Jack Bates
    Replies:
    0
    Views:
    281
    Jack Bates
    May 2, 2011
Loading...

Share This Page