Spaces:
Build error
Build error
Download src/utils.py from tinyboy1993/LianDan-Tang: direct link, hf CLI and curl.
- Browser
- Download file 492 Bytes
-
https://huggingface.co/spaces/tinyboy1993/LianDan-Tang/resolve/main/src/utils.py
- Command line
-
hf download hf://spaces/tinyboy1993/LianDan-Tang/src/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/tinyboy1993/LianDan-Tang/resolve/main/src/utils.py
492 Bytes
| import json | |
| from typing import Optional,List,Dict | |
| class Dict2Obj(dict): | |
| def __getattr__(self, key): | |
| if key not in self: | |
| return None | |
| else: | |
| value = self[key] | |
| if isinstance(value,dict): | |
| value = Dict2Obj(value) | |
| return value | |
| def load_json(file_path:str) ->Dict2Obj: | |
| with open(file_path,"r",encoding="utf-8")as f: | |
| return Dict2Obj(json.loads(f.read())) | |
| other_data = load_json("./data/other.json") | |