Created
August 22, 2023 18:11
-
-
Save zmej-serow/3818bdb1a39df297c317f3a27afadee7 to your computer and use it in GitHub Desktop.
Dot notation access for dicts
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 DotNotation(dict): | |
""" | |
Access dictionary attributes via dot notation | |
""" | |
__getattr__ = dict.get | |
__setattr__ = dict.__setitem__ | |
__delattr__ = dict.__delitem__ | |
test = {"name": "value"} | |
data = DotNotation(test) | |
print(data.name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment