Initial commit
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import json
|
||||
import os
|
||||
|
||||
def load_config(config_file: str) -> dict:
|
||||
"""从指定的 config_file 加载配置,若不存在则返回空字典。"""
|
||||
if os.path.exists(config_file):
|
||||
try:
|
||||
with open(config_file, 'r', encoding='utf-8') as f:
|
||||
return json.load(f)
|
||||
except:
|
||||
pass
|
||||
return {}
|
||||
|
||||
def save_config(config_data: dict, config_file: str) -> bool:
|
||||
"""将 config_data 保存到 config_file 中,返回 True/False 表示是否成功。"""
|
||||
try:
|
||||
with open(config_file, 'w', encoding='utf-8') as f:
|
||||
json.dump(config_data, f, ensure_ascii=False, indent=4)
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
Reference in New Issue
Block a user