Skip to content

Instantly share code, notes, and snippets.

@samclane
Created December 4, 2019 17:52
Show Gist options
  • Save samclane/1b441132ba20084bd66d6dfaed071c57 to your computer and use it in GitHub Desktop.
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.
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