Skip to content

Instantly share code, notes, and snippets.

@rctay
Last active August 29, 2015 14:08
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 rctay/e8c7f6e71b5096f257ea to your computer and use it in GitHub Desktop.
Save rctay/e8c7f6e71b5096f257ea to your computer and use it in GitHub Desktop.
track local variables in a context
class LocalsTracker(object):
def __enter__(self):
self._locals = locals()
def __exit__(self):
locals_now = locals()
# compute diff between locals_now and self.locals...
def foo():
a = 100
with LocalsTracker():
b = 10
a = 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment