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

Peter Hansen peter at
Wed Jun 16 01:23:19 CEST 2004

Kenneth McDonald wrote:

> Traceback (most recent call last):
>   File "", line 75, in ?
>     DNOTE('''This documentation was writting using the 'doco' module.'''),
> NameError: name 'DNOTE' is not defined
> I'd prefer something like:
> 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
file, most likely.  (Check the docs or source for more on that.)

Also check the source for 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 mailing list