-1

Good Morning,

I'm re-factoring a script which will have (literally) dozens to hundreds of user configurable parameters.

The first step is, of course, to implement a GUI with check-boxes for which parameters to turn on and off, and a few entry boxes for specific configuration parameters,

My initial thought is to use something like Python's ConfigParser module, with two files. One default.cfg which does not change (so the configuration can be reset) and a second file which is dynamically changed based on what's selected/entered into the GUI (so it's persistent).

I'm wondering if there's a more elegant and pythonic way to accomplish this.

Thanks!

RightmireM
  • 2,381
  • 2
  • 24
  • 42

2 Answers2

1

I'm not an expert in setting config files, but for example, flask uses different files for storing different configs. I liked their simple way they use to keep data working by representing data as Python variables, and use python just as simple config parser.

wanderlust
  • 1,826
  • 1
  • 21
  • 25
1

ConfigParser and json are both common choices for storing structured configuration data that Python needs to both read and write programmatically, and the pattern of a default file to initialize from and a "dirty" file to store a copy of the user's chosen settings is also good, since they are both human readable that way.

An alternative is to use a single large JSON for storing both the default settings under a top level key and the user's settings under a user-specific key, but this is a personal preference.

If you're looking to store Python objects as configuration values, you might take a look at the shelf module, which combines pickle with an "on-disk" key-value store.

Before going to town building your UI, try to decide if something like Gooey will do the job for you.

mobiusklein
  • 1,403
  • 9
  • 12