Another way using builtin libs:
import json
from types import SimpleNamespace
my_dict = {
"number": 0,
"thing": True,
"foo": {
"bar": {
"thing": "string"
}
}
}
dumped_data = json.dumps(my_dict)
result = json.loads(dumped_data, object_hook=lambda x: SimpleNamespace(**x))
result.number
>> 0
result.foo.bar.thing
>> string
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…