Getting terse tracebacks?

Discussion in 'Python' started by Roy Smith, Jan 1, 2006.

  1. Roy Smith

    Roy Smith Guest

    Is there any way to make the traceback printer built into the
    interpreter elide all the directories in pathnames (like strip_dirs()
    does for the profiler)?

    I'm working in a deep directory tree, and the full pathnames to my
    python source files are pushing 150 characters. I either need a
    laptop with a wider screen, or younger eyes so I can read a smaller
    font :)
    Roy Smith, Jan 1, 2006
    #1
    1. Advertising

  2. Roy Smith

    Guest

    Roy> Is there any way to make the traceback printer built into the
    Roy> interpreter elide all the directories in pathnames (like
    Roy> strip_dirs() does for the profiler)?

    There's a compact traceback printer in asyncore (compact_traceback). I used
    it as the basis for a compact stack printer:

    import os
    import sys

    # adapted from asyncore.compact_traceback()
    def compact_stack(start=0, size=100):
    """build a compact stack trace from frame start to end"""
    f = sys._getframe(start+1) # don't include this frame
    info = []
    while f:
    fn = os.path.normpath(os.path.abspath(f.f_code.co_filename))
    info.append((fn, f.f_code.co_name, f.f_lineno))
    f = f.f_back

    # eliminate any common prefix the filenames share
    info = [(f.split(os.sep)[-1], c, l) for (f, c, l) in info]

    return '\n'.join(['[%s|%s|%d]' % x for x in info[:size]])

    def print_compact_stack(f=sys.stderr, start=0, size=100):
    print >> f, compact_stack(start+1, size)

    Skip
    , Jan 2, 2006
    #2
    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. =?ISO-8859-1?Q?Mike_M=FCller?=

    tracebacks in embedded python

    =?ISO-8859-1?Q?Mike_M=FCller?=, Jul 9, 2003, in forum: Python
    Replies:
    1
    Views:
    324
    Thomas Heller
    Jul 9, 2003
  2. Denise Vela

    Enzte is a ripoff terse chief

    Denise Vela, Jun 3, 2004, in forum: Python
    Replies:
    0
    Views:
    1,209
    Denise Vela
    Jun 3, 2004
  3. Michael P. Soulier

    getting tracebacks from traceback objects

    Michael P. Soulier, Jun 24, 2005, in forum: Python
    Replies:
    1
    Views:
    375
    Kent Johnson
    Jun 24, 2005
  4. Jens
    Replies:
    5
    Views:
    354
  5. luser droog
    Replies:
    0
    Views:
    87
    luser droog
    May 4, 2014
Loading...

Share This Page