[Tutor] Writing a Configuration Facility for an Application
denis.spir at free.fr
Fri Jan 30 15:48:49 CET 2009
Le Fri, 30 Jan 2009 14:17:34 +0100,
Willi Richert <w.richert at gmx.net> a écrit :
> I have often found that just initializing all the necessary stuff in one
> Configuration.py module. You just import it and it works.
I support this as it's far the most straightforward way!
Now, depending on the actual use, some may see that as a security issue as the module is executed. You can prevent (all?most?) problems by checking that it matches a sequence of assignments. Far easier than a real parsing... and interpreting...
Another advantage is that you a config object for free: if your module is called config.py, then you will have config.mask_file, config.latitude...
[I personly like structuring the config data into records (just named data containers):
location = Record()
location.latitude = ...
location.longitude = ...
wil give config.location config.location.latitude config.location.longitude]
la vida e estranya
More information about the Tutor