Last active
July 8, 2022 01:26
-
-
Save 0x9900/beb25081203476cc959f to your computer and use it in GitHub Desktop.
Dictionary were the elements can be accessed as attributes.
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 DictAttr(dict): | |
def __getattr__(self, key): | |
if key not in self: | |
raise AttributeError(key) | |
return self[key] | |
def __setattr__(self, key, value): | |
self[key] = value | |
def __delattr__(self, key): | |
del self[key] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment