{"id":119,"date":"2026-06-13T15:20:59","date_gmt":"2026-06-13T07:20:59","guid":{"rendered":"https:\/\/www.devfm.cn\/?p=119"},"modified":"2026-06-13T15:20:59","modified_gmt":"2026-06-13T07:20:59","slug":"class","status":"publish","type":"post","link":"https:\/\/www.devfm.cn\/?p=119","title":{"rendered":"class"},"content":{"rendered":"<pre><code class=\"language-python line-numbers\">import json\n\n\nclass DeviceConfigManager:\n\n    _deviceConfig = None\n\n    def __init__(self):\n        if self._deviceConfig is None:\n            self._deviceConfig = self.load()\n\n    def get(self, *inherit_keys):\n        if inherit_keys is None or 0 == len(inherit_keys):\n            return self._deviceConfig\n        sc = self._deviceConfig\n        for key in inherit_keys:\n            sc = sc[key]\n        return sc\n\n    def update(self, value, *inherit_keys):\n        pass\n        # if inherit_keys is None or 0 == len(inherit_keys):\n        #     raise 'inherit_keys can\\'t empty'\n        # current_key_config = self._deviceConfig\n        # for i in range(0, len(inherit_keys)):\n        #     key = inherit_keys[i]\n        #     if type(current_key_config) == dict and key not in current_key_config:\n        #         if i == len(inherit_keys) - 1:\n        #             current_key_config[key] = value\n        #         else:\n        #             current_key_config[key] = {}\n        #     else:\n        #     current_key_config = current_key_config[key]\n\n\n    def load(self):\n        device_config = None\n        with open('learn\/demo_class\/device_config.json', 'r') as device_config_file:\n            device_config = json.load(device_config_file)\n        return device_config\n\nif __name__ == '__main__':\n    device_config_manager = DeviceConfigManager()\n    print(device_config_manager)\n    print(device_config_manager.get())\n    print(device_config_manager.get('wifi_config'))\n    print(device_config_manager.get('wifi_config', 'ssid'))\n    print(device_config_manager.get('wifi_config', 'password'))\n    print(DeviceConfigManager.get('wifi_config', 'password'))\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>import json class DeviceConfigManager: _deviceConfig = &hellip; <a class=\"read-more-link\" href=\"https:\/\/www.devfm.cn\/?p=119\">Read More<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-119","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/www.devfm.cn\/index.php?rest_route=\/wp\/v2\/posts\/119","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devfm.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devfm.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devfm.cn\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devfm.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=119"}],"version-history":[{"count":1,"href":"https:\/\/www.devfm.cn\/index.php?rest_route=\/wp\/v2\/posts\/119\/revisions"}],"predecessor-version":[{"id":120,"href":"https:\/\/www.devfm.cn\/index.php?rest_route=\/wp\/v2\/posts\/119\/revisions\/120"}],"wp:attachment":[{"href":"https:\/\/www.devfm.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=119"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devfm.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=119"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devfm.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}