Skip to content

Instantly share code, notes, and snippets.

@prandelicious
Created August 26, 2017 04:58
Show Gist options
  • Save prandelicious/a2d577b52aa18222bb3497c0c80947e4 to your computer and use it in GitHub Desktop.
Save prandelicious/a2d577b52aa18222bb3497c0c80947e4 to your computer and use it in GitHub Desktop.
Sub-classing dict for better readability
class objdict(dict):
def __getattr__(self, name):
if name in self:
return self[name]
else:
raise AttributeError("No such attribute: " + name)
def __setattr__(self, name, value):
self[name] = value
def __delattr__(self, name):
if name in self:
del self[name]
else:
raise AttributeError("No such attribute: " + name)
@prandelicious
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment