style: 代码格式化
This commit is contained in:
@@ -6,17 +6,18 @@ import toml
|
||||
import json
|
||||
from copy import deepcopy
|
||||
|
||||
def load_nucleon(path: pathlib.Path, fmt = "toml"):
|
||||
|
||||
def load_nucleon(path: pathlib.Path, fmt="toml"):
|
||||
with open(path, "r") as f:
|
||||
dictdata = dict()
|
||||
dictdata = toml.load(f) # type: ignore
|
||||
dictdata = toml.load(f) # type: ignore
|
||||
lst = list()
|
||||
nested_data = dict()
|
||||
# 修正 toml 解析器的不管嵌套行为
|
||||
for key, value in dictdata.items():
|
||||
if "__metadata__" in key: # 以免影响句号
|
||||
if '.' in key:
|
||||
parts = key.split('.')
|
||||
if "__metadata__" in key: # 以免影响句号
|
||||
if "." in key:
|
||||
parts = key.split(".")
|
||||
current = nested_data
|
||||
for part in parts[:-1]:
|
||||
if part not in current:
|
||||
@@ -29,23 +30,31 @@ def load_nucleon(path: pathlib.Path, fmt = "toml"):
|
||||
for item, attr in nested_data.items():
|
||||
if item == "__metadata__":
|
||||
continue
|
||||
lst.append((Nucleon(hasher.hash(item), attr, deepcopy(nested_data['__metadata__'])), deepcopy(nested_data["__metadata__"]["orbital"])))
|
||||
lst.append(
|
||||
(
|
||||
Nucleon(
|
||||
hasher.hash(item), attr, deepcopy(nested_data["__metadata__"])
|
||||
),
|
||||
deepcopy(nested_data["__metadata__"]["orbital"]),
|
||||
)
|
||||
)
|
||||
return lst
|
||||
|
||||
def load_electron(path: pathlib.Path, fmt = "json") -> dict:
|
||||
|
||||
def load_electron(path: pathlib.Path, fmt="json") -> dict:
|
||||
"""从文件路径加载电子对象
|
||||
|
||||
Args:
|
||||
path (pathlib.Path): 路径
|
||||
fmt (str): 文件格式(可选, 默认 json)
|
||||
|
||||
|
||||
Returns:
|
||||
dict: 键名是电子对象名称, 值是电子对象
|
||||
"""
|
||||
with open(path, "r") as f:
|
||||
dictdata = dict()
|
||||
dictdata = json.load(f) # type: ignore
|
||||
dictdata = json.load(f) # type: ignore
|
||||
dic = dict()
|
||||
for item, attr in dictdata.items():
|
||||
dic[item] = (Electron(hasher.hash(item), attr))
|
||||
return dic
|
||||
dic[item] = Electron(hasher.hash(item), attr)
|
||||
return dic
|
||||
|
||||
Reference in New Issue
Block a user