Skip to content

Instantly share code, notes, and snippets.

@walison17
Last active June 20, 2020 18:03
Show Gist options
  • Save walison17/43a3c655dc58c2a4b6cafd3f79d39879 to your computer and use it in GitHub Desktop.
Save walison17/43a3c655dc58c2a4b6cafd3f79d39879 to your computer and use it in GitHub Desktop.
import json
class customdict(dict):
def __getattr__(self, name):
if name not in self:
raise AttributeError
return self[name]
def __setattr__(self, name, value):
self[name] = value
with open("example.json", "r") as f:
data = json.load(f, object_hook=customdict)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment