Any easy way to get more RE-friendly error messages from Python?
peter at engcorp.com
Wed Jun 16 01:23:19 CEST 2004
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.
More information about the Python-list