Skip to content

Instantly share code, notes, and snippets.

@escuccim
Created May 17, 2022 09:45
Show Gist options
  • Save escuccim/978ade6fbcd50752484c75895c5a6381 to your computer and use it in GitHub Desktop.
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
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