Created
February 12, 2015 13:39
-
-
Save gothma/353a803fe4bdeda66912 to your computer and use it in GitHub Desktop.
Import json as native python class
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
#!/usr/bin/env python3 | |
import json | |
class JSONConfig: | |
def __init__(self, dictionary): | |
for k, v in dictionary.items(): | |
if type(v) is dict: | |
setattr(self, k, JSONConfig(v)) | |
else: | |
setattr(self, k, v) | |
def __repr__(self): | |
return str(self.__dict__) | |
@staticmethod | |
def load(fp): | |
with open(fp) as json_file: | |
dictionary = json.load(json_file) | |
return JSONConfig(dictionary) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment