Skip to content

Instantly share code, notes, and snippets.

@pfigue
Created December 8, 2013 17:39
Show Gist options
  • Select an option

  • Save pfigue/7860771 to your computer and use it in GitHub Desktop.

Select an option

Save pfigue/7860771 to your computer and use it in GitHub Desktop.
Python Debugging Werkzeugkiste
def watch(var1):
"""
Helper to watch the value of VARIABLES (not expressions)
in the scope of calling function:
>>> k = 3
>>> watch('k')
"k" := int, "3"
Won't work with expressions like:
>>> watch('str(k)')
"""
import sys
k = sys._getframe(1)
value = k.f_locals[var1]
print '"%s" := %s, "%s"\n' % (var1, type(value).__name__, value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment