-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
It is cumbersome to propagate the command line configuration throughout the code - adding a single parameter might lead to multiple hard to find changes throughout the code.
Suggest to use use a centralized configuration object with controlled mutability:
# config.py
from types import MappingProxyType
class _Config:
def __init__(self):
self._cfg = {}
def load(self, args: dict):
self._cfg = MappingProxyType(args) # immutable view
@property
def data(self):
return self._cfg
config = _Config()
and
# main.py
import argparse
from config import config
args = vars(argparse.ArgumentParser(...).parse_args())
config.load(args)
# anywhere
from config import config
print(config.data["input_file"])
``
Metadata
Metadata
Assignees
Labels
No labels