2

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?

Philipp
  • 48,066
  • 12
  • 84
  • 109
sensae
  • 493
  • 3
  • 12

1 Answers1

3

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.

ismail
  • 46,010
  • 9
  • 86
  • 95
  • Should I be concerned about performance considering this class could be instantiated by multiple different modules? – sensae Dec 31 '10 at 08:04
  • You should absolutely make it a `singleton` so it can be instantiated only once. There are many ways to do this, see http://stackoverflow.com/questions/31875/is-there-a-simple-elegant-way-to-define-singletons-in-python – ismail Dec 31 '10 at 08:11