Created
June 8, 2018 18:10
-
-
Save ulope/176a984162ce30a4efc826d30b4af9c0 to your computer and use it in GitHub Desktop.
traceback.print_stack() but with locals
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from traceback import print_list, StackSummary, walk_stack | |
def print_stack(f=None, limit=None, file=None): | |
""" Just like `traceback.print_stack()` but shows locals of each frame. """ | |
if f is None: | |
f = sys._getframe().f_back | |
stack = StackSummary.extract(walk_stack(f), limit=limit, capture_locals=True) | |
stack.reverse() | |
print_list(stack, file=file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment