改进
This commit is contained in:
@@ -8,19 +8,34 @@ import json
|
||||
def load_nucleon(path: pathlib.Path, fmt = "toml"):
|
||||
with open(path, "r") as f:
|
||||
dictdata = dict()
|
||||
toml.load(f, dictdata) # type: ignore
|
||||
dictdata = toml.load(f) # type: ignore
|
||||
lst = list()
|
||||
for item, attr in dictdata.items():
|
||||
nested_data = dict()
|
||||
# 修正 toml 解析器的不管嵌套行为
|
||||
for key, value in dictdata.items():
|
||||
if "__metadata__" in key: # 以免影响句号
|
||||
if '.' in key:
|
||||
parts = key.split('.')
|
||||
current = nested_data
|
||||
for part in parts[:-1]:
|
||||
if part not in current:
|
||||
current[part] = {}
|
||||
current = current[part]
|
||||
current[parts[-1]] = value
|
||||
else:
|
||||
nested_data[key] = value
|
||||
# print(nested_data)
|
||||
for item, attr in nested_data.items():
|
||||
if item == "__metadata__":
|
||||
continue
|
||||
lst.append((Nucleon(hasher.hash(item), attr), dictdata["__metadata__"]["orbital"]))
|
||||
lst.append((Nucleon(hasher.hash(item), attr), nested_data["__metadata__"]["orbital"]))
|
||||
return lst
|
||||
|
||||
def load_electron(path: pathlib.Path, fmt = "json"):
|
||||
def load_electron(path: pathlib.Path, fmt = "json") -> dict:
|
||||
with open(path, "r") as f:
|
||||
dictdata = dict()
|
||||
json.load(f, dictdata) # type: ignore
|
||||
lst = list()
|
||||
dictdata = json.load(f) # type: ignore
|
||||
dic = dict()
|
||||
for item, attr in dictdata.items():
|
||||
lst.append(Electron(hasher.hash(item), attr))
|
||||
return lst
|
||||
dic["item"] = (Electron(hasher.hash(item), attr))
|
||||
return dic
|
||||
Reference in New Issue
Block a user