Skip to content

Instantly share code, notes, and snippets.

@ulope
Created June 8, 2018 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ulope/176a984162ce30a4efc826d30b4af9c0 to your computer and use it in GitHub Desktop.
Save ulope/176a984162ce30a4efc826d30b4af9c0 to your computer and use it in GitHub Desktop.
traceback.print_stack() but with locals
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