The "right" way to use config files

Tim Chase python.list at tim.thechases.com
Sat Aug 9 13:08:23 EDT 2014


On 2014-08-09 13:48, Fabien wrote:
> So I had the idea to define a super-object which parses the config
> file and input data and is given as a single parameter to the
> processing functions, and the functions take the information they
> need from it. This is tempting because there is no need for
> refactoring when I decide to change something in the config, but I
> am afraid that the program may become unmaintainable by someone
> else than myself. Another possibility would be at least to give all
> the functions access to the configfile.
> 
> To get to the point: is it good practice to give all elements of a 
> program access to the configfile and if yes, how is it done
> "properly"?

Though I don't like how it looks/feels to pass around the config in
just about any function-call that needs it, I've found that doing so
allows me to test more readily.  The alternative (putting it in a
global or some module) usually means that it's harder for me to test
in isolation.

-tkc






More information about the Python-list mailing list