Limit traceback from most recent call

  • Thread starter Brian Allen Vanderburg II
  • Start date
B

Brian Allen Vanderburg II

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
 
Y

Yinon Ehrlich

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top