Created
September 3, 2021 13:31
-
-
Save rodrigogiraoserrao/01eefefcab4f25ed5ff60661b08272dd to your computer and use it in GitHub Desktop.
A simple Python🐍 3.8+ `dict` subclass that prints a debug message before setting/getting values.
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 LogDict(dict): | |
def __setitem__(self, key, value): | |
print(f"Setting {key = } with {value = }") | |
return super().__setitem__(key, value) | |
def __getitem__(self, key): | |
print(f"Getting {key = }") | |
return super().__getitem__(key) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I used this basic modification of the
dict
built-in in this tweet, when showing that consecutive assignments (likea = b = c = 73
) happen from the left to the right.