Skip to content

Instantly share code, notes, and snippets.

@RyanRLong
Created January 14, 2020 19:32
Show Gist options
  • Select an option

  • Save RyanRLong/4bae7f767c8fab71901bf319d73de48b to your computer and use it in GitHub Desktop.

Select an option

Save RyanRLong/4bae7f767c8fab71901bf319d73de48b to your computer and use it in GitHub Desktop.
Treat a python dictionary as an object
class DictObject(dict):
def __init__(self, dict_data):
super().__init__(dict_data)
def __dir__(self):
return super().__dir__() + [str(k) for k in self.keys()]
def __repr__(self):
return f"<DictObject:}>"
def __getattr__(self, item):
return self[item]
@property
def computer_property(self):
return "I am a computed property"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment