Looking for the best storing place for configuration

Viewed 33

Let's assume that we are creating a program that makes some kind of operations on files. Input for this program is a configuration file that stores information about file paths to operating on them. So basically we should have three values within this file: all_files, files_to_analyse, and blacklisted_files.

And now we are touching the bottom line of the problem. First of all, in the program, we will generate paths and put them to all_files then someone will manually add a few paths to blacklisted_files and finally we have to filter files to analyze based on a blacklist.

My needs:

  • Configuration file easy to edit (read, write)
  • Configuration which will be able to store big amount of data, mainly lists in human readable format

For the first pitch, I've used a JSON but what is more common and better than this?

2 Answers

Many options, the best would be a yaml file, you can use PyYaml whih is similar to json but more readable, other option would be a config file from config parser

For something like that? You could just used a flat txt file. Use a delimiter (all_files: blacklisted_files: etc.) then just have a filename per line after the appropriate delimiter. Easy to edit, easy to create (you could even use find or a similar tool to create the all_files block), easy to parse. all_files = [l.strip() for l in open('configfile', 'r').readlines()]

Related