Pergunta

I hope there is a 'right' answer to this:

When using ConfigParser to manage default values in a .cfg or .ini file, should I copy everything I need to program variables and copy them back out on exit, or should I use the config.get(section, option) directly in my program as needed?

Foi útil?

Solução

This is really a matter of opinion, but my advice is to have the values out of the config relatively quickly. The code that deals with data input and the layer that deals with the actual processing should be modular enough that you can change your data source by just feeding in data from a different source. (Coupling and Cohesion)

You'll have to use your own judgement to make the call as to where to draw the line, but as a guide: if you're setting the config as a global variable and reading from there or constantly throwing it around as an argument, you're doing it wrong.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top