473,569 Members | 2,562 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 1411

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_traceb ack). I used
it as the basis for a compact stack printer:

import os
import sys

# adapted from asyncore.compac t_traceback()
def compact_stack(s tart=0, size=100):
"""build a compact stack trace from frame start to end"""
f = sys._getframe(s tart+1) # don't include this frame
info = []
while f:
fn = os.path.normpat h(os.path.abspa th(f.f_code.co_ filename))
info.append((fn , f.f_code.co_nam e, 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_s tack(f=sys.stde rr, start=0, size=100):
print >> f, compact_stack(s tart+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
1780
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 that Prothon has reached. The next release after this one in approximately a month will be the first release to incorporate the final set of frozen...
7
1780
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 python online docs one gets the idea that simply returning is OK - but I'm not sure. Is it ok to do a sys.ext()? Use 'return' or just let them run...
1
2197
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 and format_exc methods that are supposed to take a traceback object and return a formatted traceback like the default output. Unfortunately I keep...
0
1065
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 thought try: Main.Main() except Exception, err_o: print err_o.__class__.__name__, '//', err_o, '//', err_o.args that was suggested to me however it...
5
2199
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 started building this I realise what you want is impossible, we'll have to do this way instead....etc.." OK, so this is partly down to me not...
8
3307
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 to get done better. I notice on stack traces and tracebacks, an exec or execfile command appears as a stack entry -- probably as it should since it...
0
1064
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. Until now, these tools didn't pass a utility vs pain-to-use threshold. Now I've created a tool I believe to have passed that threshold, which I call...
5
2053
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 just where. Although I'm in quite a self-congratulatory mood right now, in the future, I feel like I could save a lot of time by coercing the...
5
1322
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 deferred callable, a callable that will be called at some point in the future (possibly in a different thread) and whose result or raised exception is to...
4
9805
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, by definition, contradictory. I disagree.) Consequently, I'd like to suppress Python's tracebacks if an error does occur, replacing it with a more...
0
7701
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8130
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7677
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5514
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3643
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.