Created
December 4, 2019 17:52
-
-
Save samclane/1b441132ba20084bd66d6dfaed071c57 to your computer and use it in GitHub Desktop.
List with access logging. Lets you see when items are read or written to.
This file contains 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 LoggedList(list): | |
def __init__(self, *args, name=None, **kwargs): | |
super().__init__(*args, **kwargs) | |
self._name = name | |
def __getitem__(self, item): | |
logging.info(f"{self._name} Getting item {item}") | |
super().__getitem__(item) | |
def __setitem__(self, key, value): | |
logging.info(f"{self._name} Setting item at {key} to {value}") | |
super().__setitem__(key, value) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment