ruff
This commit is contained in:
@@ -1,16 +1,19 @@
|
||||
import tomllib
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict
|
||||
|
||||
import tomllib
|
||||
|
||||
|
||||
class Config:
|
||||
def __init__(self, file_path: str = "config.toml"):
|
||||
self.path = Path(file_path)
|
||||
self._data: Dict[str, Any] = {}
|
||||
self.load()
|
||||
|
||||
def load(self):
|
||||
if not self.path.exists():
|
||||
raise FileNotFoundError(f"配置文件 {self.path} 未找到!")
|
||||
|
||||
|
||||
with open(self.path, "rb") as f:
|
||||
self._data = tomllib.load(f)
|
||||
|
||||
@@ -27,6 +30,7 @@ class Config:
|
||||
def features(self) -> dict:
|
||||
return self._data.get("features", {})
|
||||
|
||||
|
||||
# 实例化全局配置对象
|
||||
global_config = Config()
|
||||
|
||||
@@ -35,4 +39,3 @@ if __name__ == "__main__":
|
||||
print(global_config.bot.get("command"))
|
||||
print(type(global_config.bot.get("command")) is list)
|
||||
print(global_config.features)
|
||||
|
||||
Reference in New Issue
Block a user