I have an application that can be started using some user preferences. To do so, I use the ConfigParser
class from the built-in package ConfigParser
. I derived a subclass of ConfigParser
that implements the __getitem__
and __setitem__
methods in order to get/set some preferences items without having to specify each time their respective section, subsections and option.
As some of those preferences (working directory, logging level ...) are quite sensible for my code, I would like to check them every time one of their items is modified. To do so, I currently think about two approaches:
writing a method that check every item of my preferences each time one of them is modified. Quite simple but not very efficient as every time one item is changed the whole preferences are checked.
writing a check_item method for each preferences item (check_logger, check_working_directory, check_blabla ...) and each time an item is set the corresponding checker will be called using
getattr(self,'check_%s' % item)(item)
I would tend to think that the second approach is better than the first one.
Would you see some alternatives to those designs ?
thank you very much
Eric