Created
September 12, 2018 17:07
-
-
Save rlabbe/e70f4320161d426d5e49d88a1925e491 to your computer and use it in GitHub Desktop.
AttrDict
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 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