def load(self, profile_json): """ Load an existing JSON profile @profile_json: dict (e.g. from json.load() or json.loads()) """ logger.debug("Loading profile JSON data structure into class object") self.__dict__.update(DotDict(profile_json))
def get_profile_from_file(self, user_structure_json_path): """ Load the json structure into a 'DotDict' so that attributes appear as addressable object values Usually used with load(). """ logger.debug("Loading default profile JSON structure from {}".format(user_structure_json_path)) if not os.path.isfile(user_structure_json_path): dirname = os.path.dirname(os.path.realpath(__file__)) path = dirname + "/" + user_structure_json_path else: path = user_structure_json_path return DotDict(json.load(open(path)))
def test_dotdict_sublevel(self): x = DotDict({"test": {"sub": {"test"}}}) print(x.test.sub)
def test_dotdict(self): x = DotDict({"test": "test"}) print(x.test)