Created
November 25, 2021 21:47
-
-
Save afr-dt/5885468f6c2248ecc05a2205c01fd7c6 to your computer and use it in GitHub Desktop.
accessing_dict_keys_like_an_attribute
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 AttrDict(dict): | |
def __init__(self, *args, **kwargs): | |
super(AttrDict, self).__init__(*args, **kwargs) | |
self.__dict__ = self | |
config = AttrDict() | |
# Example | |
config['name'] | |
config['last_name'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment