Skip to content

Instantly share code, notes, and snippets.

@taiya
Created September 22, 2021 17:28
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 taiya/3861daeb069adc1d6fcc5811a59063b1 to your computer and use it in GitHub Desktop.
Save taiya/3861daeb069adc1d6fcc5811a59063b1 to your computer and use it in GitHub Desktop.
class AttrDict(dict):
__getattr__ = dict.__getitem__
__setattr__ = dict.__setitem__
mydict = {
'a': 'foo',
'b': 'bar',
}
mydict = AttrDict(mydict)
print(mydict.a)
mydict.b = 'zee'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment