I have terrible doubts regarding python config file approach.
I am creating a program with a GUI (PyQt). The program loads some settings from a .cfg file using the configparser module. And the user can edit these settings from the GUI with the user preferences widget. When the preferences widget is closed the .cfg file is saved but I don't know how to update the rest of the program using the updated settings values.
I will try to explain with an example:
- I launch the program. It create a ConfigParser() named config and read settings.cfg.
- The program retrieve the value of the option 'clock_speed' (let's say it is 5) from config and set clkSpd = 5.
- I click on Edit -> Preferences and change the clock speed via a QSpinBox to 8.
- I close the Preferences windget, settings.cfg is saved, the value of the option 'clock_speed' is now 8.
- BUT in its module, clkSpd is still 5.
I know I can just load the settings, edit them, save them and reload all settings each time I close the Preferences window. It's simple but not very beautiful.
Is there a classic and effficiant approach for config files in read/write mode ?
Thanks by advance.