Created
May 17, 2022 09:45
-
-
Save escuccim/978ade6fbcd50752484c75895c5a6381 to your computer and use it in GitHub Desktop.
Class that behaves like a dict but allows values to be accessed as properties
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 PDict: | |
def __init__(self, **kwargs): | |
for key, value in kwargs.items(): | |
self.__dict__[key] = value | |
def __getitem__(self, key): | |
return self.__dict__.get(key) | |
def __setitem__(self, key, value): | |
self.__dict__[key] = value | |
def __str__(self): | |
return str(self.__dict__) | |
def __repr__(self): | |
return self.__str__() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment