473,503 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting terse tracebacks?

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 :-)
Jan 2 '06 #1
1 1406

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_filen ame))
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 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
1773
by: Mark Hahn | last post by:
Prothon is pleased to announce another major release of the language, version 0.1.2, build 710 at http://prothon.org. This release adds many new features and demonstrates the level of maturity...
7
1775
by: Maxwell Hammer | last post by:
Hi all, This is related to an earlier post 'Help with thread related tracebacks'...for which I have had no feedback yet :-( How should a thread complete i.e. how should it exit? Reading the...
1
2187
by: Michael P. Soulier | last post by:
Hello, For a GUI app I've tried resetting sys.excepthook to my own exceptionhandler bound method, which accepts a type, value and traceback object. Now, the traceback module has print_exc...
0
1064
by: Timothy Smith | last post by:
iw ant to use a singel try except statment with my main app loop in the middle and catch all tracebacks and email them to myself as a bug report. however it seems a little more tricky then i...
5
2191
by: Paul H | last post by:
How do you folks get a reliable and complete brief of what is required before development starts? I am forever going back to a client once a project has started saying "Hang on, now that I've...
8
3304
by: R. Bernstein | last post by:
In doing the extension to the python debugger which I have here: http://sourceforge.net/project/showfiles.php?group_id=61395&package_id=175827 I came across one little thing that it would be nice...
0
1058
by: Nathan | last post by:
Hi folks! Throughout my python development career, I've occasionally made various developer tools to show more information about assertions or exceptions with less hassle to the programmer. ...
5
2048
by: James Stroud | last post by:
Hello All, The built-in mac osx vecLib is segfaulting in some cases--A very fun fact to find out the hard way over two nights of work. I also spent an embarrassing amount of time figuring out...
5
1317
by: George Sakkis | last post by:
I'm reading the docs on sys.exc_info() but I can't tell for sure whether I'm using it safely to get a snapshot of an exception and reraise it later. The use case is a class which acts like a...
4
9794
by: Steven D'Aprano | last post by:
I'm writing a command-line application that is meant to be relatively user friendly to non-technical users. (Some wags might like to say that "user friendly" and "command-line application" are,...
0
7204
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7342
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7464
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5586
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5018
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3171
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3162
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
741
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
391
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.