Skip to content

Instantly share code, notes, and snippets.

@bpicolo
Created July 21, 2014 23:39
Show Gist options
  • Save bpicolo/b77f43cbf66c515dc9f3 to your computer and use it in GitHub Desktop.
Save bpicolo/b77f43cbf66c515dc9f3 to your computer and use it in GitHub Desktop.
Watch for dict item setting in python
class TracerDict(object):
"""Watches changes on a dict for the keys passed in"""
def __init__(self, check_keys):
self.check_keys = check_keys
self._dict = {}
def __setitem__(self, key, value):
if key in self.check_keys:
import pdb; pdb.set_trace()
self._dict[key] = value
def __getitem__(self, key):
return self._dict[key]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment