Limit traceback from most recent call
Yinon Ehrlich
yinon.me at gmail.com
Mon Dec 15 08:29:00 EST 2008
On Dec 14, 8:07 pm, Brian Allen Vanderburg II
<BrianVanderbu... at aim.com> wrote:
> I've looked at traceback module but I can't find how to limit traceback
> from the most recent call if it is possible. I see that extract_tb has
> a limit parameter, but it limits from the start and not the end.
> Currently I've made my own traceback code to do this but wonder if
> python already has a way to do this build in:
>
> def format_partial_exc(limit=None):
>
> (type, value, tb) = sys.exc_info()
>
> items = traceback.extract_tb(tb)
>
> if limit:
>
> items = items[-limit:] # Get last 'limit' items and not first
>
> result = 'Traceback (most recent call last):\n'
>
> items = traceback.format_list(items)
>
> for i in items:
>
> result += i # Newline already included
>
> result += type.__name__ + ': ' + str(value)
>
> return result
>
> Is this possible currently from traceback or other python module?
>
> Brian A. Vanderburg II
Hi,
The interface of extract_tb is:
traceback.extract_tb(tb, limit=None)
try to play with the 'limit' argument
Good luck,
Yinon
More information about the Python-list
mailing list