[Python] Can I get the Python interpreter to print stack traces with one line per frame rather...

Discussão em 'Python' iniciado por Stack, Abril 23, 2025.

  1. Stack

    Stack Membro Participativo

    When an exception is raised in Python, we get something like:

    Location
    source line
    Location
    source line
    Location
    source line


    yet - I would rather have one line per "stack frame", e.g.:

    Location: source line
    Location: source line
    Location: source line


    can I get the Python interpreter to print stack traces this way? To be clear: I'm not asking how to print a stack trace this way in my own code; I'm asking about the stack trace the interpreter prints.

    Notes:

    • Assume Python 3.x . If the answer further depends on the Python subversion - that's fine, but please say so.
    • I don't care that much about the spacing and separators used, but do care about it joining the lines.
    • I realize I can pipe standard error into a sed call and fix this manually, but I'd rather not do that, plus - would rather not run the risk of catching something else with the regular expression for stack traces.

    Continue reading...

Compartilhe esta Página