Handling high number of configuration parameters in python

Viewed 27

In my Machine Learning project I have a high number of parameters that are loaded from a configuration file, e.g. a YAML file. I wonder, is there any best practice on how to integrate them in the codebase other than a number of 'setup_by_cfg' functions? I was thinking about classmethods, but then the implementation gets coupled to the parameter file which could be problematic?

# option A
# setup_by_cfg.py

def setup_a(cfg):
    return A(a=cfg.a, b=cfg.b)

def setup_b(cfg):
    ...
# option B
# coupled in class implementation

class A:
    # ...
    @classmethod
    def from_cfg(cls, cfg):
        return cls(a=cfg.a, b=cfg.b)


class B:
    # ...
    @classmethod
    def from_cfg(cls, cfg):
        # ...
0 Answers
Related