My goal is a Setting class where:
- I can access parameters by name (not key lookup)
- I can serialize the parameters to JSON
Something that can do: object.param <--> dict['param']
I thought I could use namedtuples, but micropython doesn't do:
Code: Select all
namedtuple._asdict()
Code: Select all
settings_dict = {"param": 1} # loaded from JSON
class Setting(object):
def __init__(self):
self.param = None
self.__dict__.update(settings_dict)
def save(self):
global settings_dict
settings_dict = self.__dict__
# save to json
Am I missing the obvious or is there no clean way of doing this?