Shorter tracebacks

Peter Otten __peter__ at web.de
Sun Dec 14 14:05:59 EST 2008


Peter Otten wrote:

> That's none of __future__'s business, I think. Python offers a hook which
> you can modify:
> 
>>>> import sys, traceback
>>>> from functools import partial
>>>> sys.excepthook = partial(traceback.print_exception, limit=5)

I just stumbled upon

>>> import sys
>>> sys.tracebacklimit
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'tracebacklimit'
>>> sys.tracebacklimit = 2
>>> def f(): f()
...
>>> f()
Traceback (most recent call last):
  File "<stdin>", line 1, in f
  File "<stdin>", line 1, in f
RuntimeError: maximum recursion depth exceeded

Peter



More information about the Python-list mailing list