Created
July 21, 2014 23:39
-
-
Save bpicolo/b77f43cbf66c515dc9f3 to your computer and use it in GitHub Desktop.
Watch for dict item setting in python
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
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