0

I would like to virtualize configuration so my classes don't know anything about how setting arrive. Normally I pass classes a dictionary with everything needed to get up and running. This approach has been helpful in production and testing as the test cases aren't tied to specific data files and the code is unaware of the environment it is running in.

The problem arises when the configuration data gets more extensive; for instance the files grow large or information needs to be passed to subcomponents that also have complex configurations. In these cases a single configuration file no longer makes sense.

It would be nice to add directives to the config files that tell a preprocessor where to pull additional setting from. For instance the following json:

{
  "a" : "plain old json string",
  "b" : ${LoadFromJsonFile(<file path>)},
  "c" : ${LoadCsvAsListOfDict(<file path>)}
{

Is there a library for this or is this something I should write on my own or is this idea problematic?

btw - I looked at the related stackexchange questions and didn't see anything similar and/or specific to python. There was one suggest to use XML with Ant but I would prefer to stick with a python environment.

Toaster
  • 1,911
  • 2
  • 23
  • 43
  • The only problem I can think of is not a Python issue. File paths in config files can be problematic later should you need to move the filesystem location. To avoid, use relative paths `../anotherdir/anotherfile` not `/somewhere/anotherdir/anotherfile`. Obviously, if you implement this your config file is no longer a valid JSON file. `"c" : "${Load...(...)}"` may be preferable to preserve JSON syntax and (for example) `json.load` compatibility. – nigel222 Oct 27 '15 at 11:08
  • [My answer to another Stackoverflow question](http://stackoverflow.com/questions/31330782/how-to-handle-large-number-of-configuration-parameters-across-a-program-conceptu/31351052#31351052) might provide some food for thought. – Ciaran McHale Oct 27 '15 at 21:07
  • Thank you for your comments. – Toaster Oct 28 '15 at 11:18

0 Answers0