Skip to content

Instantly share code, notes, and snippets.

@zmej-serow
Created August 22, 2023 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zmej-serow/3818bdb1a39df297c317f3a27afadee7 to your computer and use it in GitHub Desktop.
Save zmej-serow/3818bdb1a39df297c317f3a27afadee7 to your computer and use it in GitHub Desktop.
Dot notation access for dicts
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