Skip to content

Instantly share code, notes, and snippets.

@rlabbe
Created September 12, 2018 17:07
Show Gist options
  • Save rlabbe/e70f4320161d426d5e49d88a1925e491 to your computer and use it in GitHub Desktop.
Save rlabbe/e70f4320161d426d5e49d88a1925e491 to your computer and use it in GitHub Desktop.
AttrDict
class AttrDict(dict):
"""
dict that lets you access any key via attribute:
x['hi'] or x.hi
"""
def __init__(self, *args, **kwargs):
super(AttrDict, self).__init__(*args, **kwargs)
self.__dict__ = self
def __repr__(self):
import pprint
return pprint.pformat(dict(self), indent=1, width=120)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment