470,815 Members | 1,340 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,815 developers. It's quick & easy.

Any easy way to get more RE-friendly error messages from Python?

I'm setting myself up to use Python with jEdit (after trying
jed, VIM, others...urggh.) One small problem I'm having is
that while jEdit has a nice plugin called Console which can
be set up to run python scripts, and parse the result for
errors which can then be used to put the editing cursor
directly on the offending line, it doesn't play so well with
the multiline error messages that Python generates. (Actually,
I've never liked them a lot myself :-) ) The easiest way
to deal with this is probably to hack Python to put out
its error messages in a different format: I can think of
a couple of approaches, but they seem a little kludgey,
so I thought I'd solicit suggestions from the group.

So instead of error output that looks like this:

Traceback (most recent call last):
File "__init__.py", line 75, in ?
DNOTE('''This documentation was writting using the 'doco' module.'''),
NameError: name 'DNOTE' is not defined

I'd prefer something like:

PyError:__init__.py:75:NameError: name 'DNOTE' is not defined

(with, obviously, one such line for each element of the traceback.)
The thoughts that come to me first are:

1) Write some sort of wrapper to python.
2) Find and change an internal python hook.

I'm wondering what other ways of approaching this might
be suggested--both of the above have certain elements
I dislike.
Thanks,
Ken
Jul 18 '05 #1
1 1459
Kenneth McDonald wrote:
Traceback (most recent call last):
File "__init__.py", line 75, in ?
DNOTE('''This documentation was writting using the 'doco' module.'''),
NameError: name 'DNOTE' is not defined

I'd prefer something like:
PyError:__init__.py:75:NameError: name 'DNOTE' is not defined

The thoughts that come to me first are:
2) Find and change an internal python hook.


sys.excepthook() is your friend here. See the module docs
for 'sys'. You could install it "globally" using a sitecustomize.py
file, most likely. (Check the site.py docs or source for more on that.)

Also check the source for traceback.py and see how it
formats stuff now. You can easily write your own formatter
that does things differently.

You might also check the source for Zope (or was it Twisted?
sorry, can't recall... maybe it was both!) which has a one-line
exception formatter somewhere, for log files, as I recall.

-Peter
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Oliver Bryant | last post: by
16 posts views Thread by Terry McNamee | last post: by
2 posts views Thread by Thomas | last post: by
5 posts views Thread by LedZep | last post: by
1 post views Thread by Mad Scientist Jr | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.