Skip to content

Commit

Permalink
クラス名変えたり
Browse files Browse the repository at this point in the history
  • Loading branch information
misya11p committed Sep 21, 2024
1 parent 12fd38e commit a951e8d
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions utils/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,27 @@
from typing import Dict, Any


class Config(dict):
class CustomDict(dict):
def __init__(self, config: Dict):
super().__init__(config)

def __getattr__(self, name: str) -> Dict | Any:
value = self[name]
if isinstance(value, dict):
return Config(value)
return CustomDict(value)
else:
return value

def __getitem__(self, key: Any) -> Any:
item = super().__getitem__(key)
if isinstance(item, dict):
return CustomDict(item)
else:
return item


root = Path(__file__).parent.parent
path_config = root / "config.json"
with open(path_config, "r") as f:
config_json = json.load(f)
config = Config(config_json)
config = CustomDict(config_json)

0 comments on commit a951e8d

Please sign in to comment.