[Python-ideas] Negative limit for traceback.*

Thomas Allen jsbfox at gmail.com
Sun Aug 24 19:48:51 CEST 2014


I'd like to propose adding the ability to extract last n stack trace
entries from a traceback using functions from traceback module. Simply
put, passing limit=-n would make functions to return (or print or
yield) last abs(n) entries. No-brainer implementation for extract_tb:

    extracted = list(_extract_tb_iter(tb, limit=(limit, None)[limit < 0]))
    if limit is not None and limit < 0:
        return extracted[limit:]
    return extracted

The motivation: http://stackoverflow.com/q/25472412/2301450


More information about the Python-ideas mailing list