Search code examples
pythonconfigparser

Placement of config file reading


I'm developing a CLI python program and I'm using ConfigParser. I know this is probably more to preference than anything else, but currently my configuration reading script is in config.py in a package. Would I be better off placing my configuration reading information in __init__.py?


Solution

  • My preference would to put it in config.py too, because __init__.py should be minimal, separate classes should be in separate files to lower maintainance overhead. So I would go ahead and create a Configuration class like this;

    class Configuration:
    
        def getVersion():
            ....
    
        def getFoo()
            ....
    
        def getBar()
            ....
    

    etc.